Sometimes a value is missing. SQL writes a missing value as NULL, a bit like nil in Go. In the shop, the Gift card has no category: its category is NULL.
NULL means "unknown", so a comparison with it is never true. category = NULL is unknown for every row, even for the gift card, and WHERE keeps only the rows whose test is true, so it finds nothing. To test for a missing value, SQL has IS NULL, and its opposite, IS NOT NULL:
var query = "SELECT name, price " +
"FROM products " +
"WHERE category IS NOT NULL "
This query keeps the 7 products that have a category. In this lesson you write two queries, and the check prints both, with show(db, query) and show(db, query2). Your code must print exactly this:
name | category (0 rows) name | category Gift card | NULL (1 row)
Your task: the connection db to shop.db is already there. In query, look for the products without a category with = NULL and see that it finds nothing. In query2, find them the right way, with IS NULL.
Assignment
Follow the Coding Tutorial to write both queries, one clause per line: SELECT, FROM, then a WHERE.
Hint
NULL goes without quotes: 'NULL' in quotes is just a four-letter text. query2 has the same SELECT and FROM lines as query; only the WHERE changes. End each string with a space so the clauses don't run together, and put + after every piece but the last. Go builds the whole file before it runs, so nothing prints until both queries are finished.
Free plan: 30 tutor messages. PRO is unlimited.
