Reputation: 111
I have this table
NAME|VALUE|
T | A
T | NONE
T | B
S | NONE
where the value NONE is a NULL value in real.
NAME|VALUE|
T | A
T | B
S | NONE
Do you know to do such query?
Thanks in advance for your help.
Upvotes: 2
Views: 97
Reputation: 16417
Is there a max of two values? That is, is only possible to get a single value, "NONE", or one of each. If so, you can do this:
SELECT name, COALESCE(MAX(NULLIF(value, 'NONE'), 'NONE')
FROM <tablename>
GROUP BY name
I believe the following will work for the general case (one or more non-NONE values possible):
SELECT name, value FROM <tablename> WHERE value <> 'NONE'
UNION
SELECT name, value FROM <tablename> WHERE value = 'NONE'
AND name NOT IN (SELECT name FROM <tablename> WHERE value <> 'NONE')
Upvotes: 1
Reputation: 837966
Here's one way you could do it:
SELECT T1.NAME, T2.VALUE
FROM (SELECT DISTINCT name FROM Table1) AS T1
LEFT JOIN (SELECT * FROM Table1 WHERE VALUE IS NOT NULL) AS T2
ON T1.NAME = T2.NAME
Results:
S NULL
T A
T B
Upvotes: 1