NULLIF

From SQLZOO
Revision as of 11:28, 28 October 2012 by Peter (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Compatibility
NULLIF(f1,f2)
EngineOKAlternative
ingresYes
mysqlYes
oracleYes
postgresYes
sqlserverYes

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
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense