AmbifulWorksheets
Cheat sheet
CBSE · Class 11 · Informatics Practices

Introduction to Structured Query Language (SQL)

SQL on one table: command and data types, SELECT with WHERE, BETWEEN, IN, LIKE, NULL, DISTINCT and ORDER BY.

Key ideas

Remember

SELECT, in orderSELECT [DISTINCT] c FROM t WHERE … ORDER BY c [DESC];
BETWEENMarks 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, ORFALSE AND unknown is FALSE; TRUE OR unknown is TRUE; otherwise unknown, so the row is left out
A result’s sizedegree = columns shown; cardinality = rows kept

Watch out

Worked example

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