SQL on one table: command and data types, SELECT with WHERE, BETWEEN, IN, LIKE, NULL, DISTINCT and ORDER BY.
| SELECT, in order | SELECT [DISTINCT] c FROM t WHERE … ORDER BY c [DESC]; |
| BETWEEN | Marks BETWEEN 40 AND 60 is Marks >= 40 AND Marks <= 60 |
| LIKE | 'K%' starts with K; '%a' ends with a; '_a%' has a 2nd; '____' 4 letters |
| NULL with AND, OR | FALSE AND unknown is FALSE; TRUE OR unknown is TRUE; otherwise unknown, so the row is left out |
| A result’s size | degree = columns shown; cardinality = rows kept |
Table: ITEM
ItemCode | IName | Category | Price | Qty
I207 | Water Bottle | Daily Use | 110 | 30
I209 | Umbrella | Daily Use | 230 | 45
I210 | Pencil | Stationery | 10 | 50
I216 | Marker | Stationery | 25 | 25
I221 | Eraser | Stationery | 10 | 35
I232 | Lunch Box | Daily Use | 155 | 40
I239 | Gel Pen | Stationery | 30 | 15
I240 | Ruler | Stationery | 20 | 50
I255 | Glue Stick | Office | 45 | 35
SELECT IName FROM ITEM WHERE Category IN ('Daily Use') ORDER BY IName;
Write the output, names separated by commas, in order.
Working: IN keeps a row whose value is any one in the list; ORDER BY Name sorts alphabetically
Answer: Lunch Box, Umbrella, Water Bottle