Lesson 4 Β· Reference Card

SQL Quick Reference

Everything you need to write SQL in Microsoft Access SQL View. Keep this open while you work.

βš™οΈ
How to Open SQL View in Access
1
Click Create in the ribbon β†’ click Query Design
2
A "Show Table" dialog appears β€” click Close (don't add any tables)
3
Click the View dropdown in the top-left of the ribbon β†’ select SQL View
4
Type your SQL statement in the box. Click Run (the red exclamation mark !) to execute.
5
To write a new query: go to View β†’ SQL View again. Select all text (Ctrl+A) and delete it. Type your new statement.
⚠️ Access SQL quirks: Use double-quotes around text values (e.g., "Pop"). The wildcard character is * (not %). LIKE uses * for "any characters".
πŸ“‹
SELECT β€” Choose Columns

Choose which fields (columns) to show. Use * for all fields.

SELECT * FROM Songs;
SELECT Title, Artist FROM Songs;
β†’ Result (SELECT Title, Artist)
TitleArtist
Neon SkylineThe Midnight
Bad HabitsEd Sheeran
……
πŸ”
WHERE β€” Filter Rows

Only return rows that match the condition.

SELECT * FROM Songs WHERE Genre = "Pop";
SELECT * FROM Songs WHERE Streams > 5000000;
β†’ Only rows where Genre = "Pop"
TitleGenreStreams
Blinding LightsPop12000000
Bad HabitsPop9800000
↕️
ORDER BY β€” Sort Results

ASC = A→Z or lowest→highest. DESC = Z→A or highest→lowest.

SELECT Title, Streams FROM Songs ORDER BY Streams DESC;
SELECT * FROM Songs ORDER BY Title ASC;
πŸ”—
AND / OR β€” Combine Conditions

AND = both must be true. OR = either can be true.

-- AND: Pop songs with 1M+ streams SELECT * FROM Songs WHERE Genre = "Pop" AND Streams > 1000000;
-- OR: Pop OR Rock songs SELECT * FROM Songs WHERE Genre = "Pop" OR Genre = "Rock";
πŸƒ
LIKE β€” Wildcard Matching

Use * to match any characters. Use ? for exactly one character.

-- Starts with "The" SELECT * FROM Songs WHERE Title LIKE "The*";
-- Contains "rain" SELECT * FROM Songs WHERE Title LIKE "*rain*";
↔️
BETWEEN β€” Range Filter

Shorthand for >= AND <=. Both end values are included.

SELECT * FROM Songs WHERE ReleaseYear BETWEEN 2019 AND 2021;
SELECT * FROM Songs WHERE DurationMins BETWEEN 3 AND 4;
⚑
Putting It All Together

You can combine SELECT, WHERE, ORDER BY in one statement. The order always goes: SELECT β†’ FROM β†’ WHERE β†’ ORDER BY.

-- Pop songs with 1M+ streams, sorted by streams (most first) SELECT Title, Artist, Streams FROM Songs WHERE Genre = "Pop" AND Streams > 1000000 ORDER BY Streams DESC;
KeywordWhat It DoesRequired?
SELECTChoose which fields to showβœ… Always first
FROMSpecify which table to queryβœ… Always second
WHEREFilter which rows to returnOptional
AND / ORCombine multiple conditionsOptional
ORDER BYSort the resultsOptional (always last)
⚠️
Common Mistakes to Avoid
❌ Wrong wildcard
WHERE Title LIKE "The%" ← wrong!

Access uses * not %. Use "The*"

❌ Single quotes
WHERE Genre = 'Pop' ← wrong!

Access needs double-quotes: "Pop"

❌ Wrong keyword order
WHERE … FROM … ← wrong!

Always: SELECT β†’ FROM β†’ WHERE β†’ ORDER BY

❌ Missing semicolon
SELECT * FROM Songs ← missing ;

End every statement with a semicolon ;