NULLIF
From SQLZoo
NULLIF(f1,f2) | ||
---|---|---|
Engine | OK | Alternative |
ingres | Yes | |
mysql | Yes | |
oracle | Yes | |
postgres | Yes | |
sqlserver | Yes |
NULLIF
NULLIF returns NULL if the two arguments are equal; otherwise NULLIF returns the first argument.
NULLIF(x,y) = NULL if x=y NULLIF(x,y) = x if x != y
NULLIF can be used to replace a specific value with NULL. In this example the party Lab is replaced with NULL.
SELECT name, party
,NULLIF(party,'Lab') AS aff
FROM gisq.msp WHERE name LIKE 'C%'
SELECT name, party
,NULLIF(party,'Lab') AS aff
FROM msp WHERE name LIKE 'C%'
See also
Language: | English • Deutsch |
---|