Selecting NULL values.
From SQLZoo
This table shows political parties contesting Scottish elections.
| code | name | leader |
|---|---|---|
| Com | Communist | null |
| Con | Conservative | McLetchie MSP, David |
| Green | Green | null |
| Lab | Labour | Dewar MSP, Rt Hon Donald |
| LD | Liberal Democrat | Wallace QC MSP, Mr Jim |
| NLP | Natural Law Party | null |
| SNP | Scottish National Party | Salmond MSP, Mr Alex |
| SSP | Scottish Socialist Party | null |
| SWP | Socialist Workers Party | null |
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