Selecting NULL values.

From SQLZoo

This table shows political parties contesting Scottish elections.

party
codenameleader
ComCommunistnull
ConConservativeMcLetchie MSP, David
GreenGreennull
LabLabourDewar MSP, Rt Hon Donald
LDLiberal DemocratWallace QC MSP, Mr Jim
NLPNatural Law Partynull
SNPScottish National PartySalmond MSP, Mr Alex
SSPScottish Socialist Partynull
SWPSocialist Workers Partynull

Sometimes NULL values are given in tables, this might be because the data is unknown or is inappropriate. In the Parliament database a NULL value for party in the MSP table indicates that the MSP concerned is not a member of any of the parties. In the party table a NULL value is used where the party does not have an official leader - or I couldn't find one. I rather like it that the Greens and the Scottish Socialist Party don't seem to have leaders - and it suits my purposes.

We can use the phrase IS NULL to pick out fields. We can use IS NOT NULL similarly.

The SELECT statement returns results from a table. With a WHERE clause only some rows are returned.

SELECT code, name FROM party
  WHERE leader IS NULL
  • Served by: ben at 2026-07-03T02:37