Practical SQL Query Examples

Test yourself on SQL with exam style questions, marked instantly.

Flashcards that come back just before you would forget them.

A revision plan that remembers what you know and shows what to do next.

See which topics you have nailed and which need another look.

Quiz yourself on SQLGet your flashcardsBuild my revision planTrack my progress

Practical SQL Query Examples

Given this Students table:

StudentIDNameAgeCityScore
1Alice15London85
2Bob17Manchester72
3Charlie16London91
4Diana17Leeds68
5Eve15London95

Query 1: All London students

SELECT Name, Age FROM Students WHERE City = "London"
-- Returns: Alice (15), Charlie (16), Eve (15)

Query 2: Students aged 16+ sorted by score (highest first)

SELECT Name, Score FROM Students
WHERE Age >= 16
ORDER BY Score DESC
-- Returns: Charlie (91), Bob (72), Diana (68)

Query 3: London students with score over 90

SELECT * FROM Students
WHERE City = "London" AND Score > 90
-- Returns: Charlie (91), Eve (95)

Query 4: Students from London OR Manchester

SELECT Name, City FROM Students
WHERE City = "London" OR City = "Manchester"
-- Returns: Alice, Bob, Charlie, Eve

Make this stick

Signing in gives access to all PrepWise features.

PrepWise is a trading name of A3M Quality Solutions Limited, registered in England and Wales, company number 14959172. Registered office: 202 Stroud Road, Gloucester, GL1 5LA. ICO registration ZC267069.