An interactive lesson and quiz on Records, Tables, and SQL.
Please enter your name to begin.
Optional: 5-Minute Crash Course
Short on time? Watch this video first to recap SELECT, FROM, and WHERE.
Let's look at how data is structured in a database table.
Think of a database table like a spreadsheet. It has columns (called Fields) and rows (called Records).
| StudentID (Field) | FirstName (Field) | FormTutor (Field) |
|---|---|---|
| 1001 | Jane | Mr. Jones |
| 1002 | David | Ms. Patel |
| 1003 | Amir | Mr. Jones |
This table has 3 Fields and 3 Records. The highlighted row is a single record for the student 'David'.
SQL (Structured Query Language) is the code we use to "ask questions" (or queries) to a database.
For your GCSE, you must know these three commands, which form a sentence:
SELECT FirstName, LastName
...WHAT you want to see (which columns/fields).
FROM Students
...WHERE to look for it (which table).
WHERE FormTutor = 'Mr. Jones'
...HOW to filter it (which rows/records).
"Get the first name and last name of all students in Mr. Jones' form."
SELECT FirstName, LastName
FROM Students
WHERE FormTutor = 'Mr. Jones';
Remember: Always end your full SQL query with a semicolon (;).
*) and ANDTwo more essential tools for your queries.
*)Instead of listing every field name, you can use the * (asterisk) wildcard. It's a shortcut that means "all fields".
"Get *all information* about the student with ID 1002."
SELECT *
FROM Students
WHERE StudentID = 1002;
AND to Combine FiltersWhat if you need to filter by two conditions? You use the AND keyword in your WHERE clause.
"Get the `Song` from the `TblMusic` table where the `Genre` is 'Rock' AND the `Year` is 1991."
SELECT Song
FROM TblMusic
WHERE Genre = 'Rock' AND Year = 1991;
Please answer all 3 questions on this page before proceeding.
(Context: The table is named ITEMS and has fields ItemCode, Stock)
SELECT FROM WHERE (Context: The table is named Results and has fields StudentID, Subject, Grade)
SELECT FROM WHERE (Context: The table is named TblPlayers and has fields PlayerName, Score, Team)
SELECT FROM WHERE Please answer all 3 questions on this page before proceeding.
SELECT ActID AND Stage
FROM TblActs
IF Day
Saturday
(Context: The field for nights is named Nights)
SELECT ALL
FROM TblBookings
IF Nights < 1
SELECT Title, Author
WHERE Genre = 'Fantasy'
FROM TblLibrary
Please answer all 3 questions on this page before proceeding.
(Context: The table is conduct. Fields are StudentName, Points)
SELECT FROM WHERE (Context: Table: TblDrone. Fields: DroneID, Mileage, DroneType)
SELECT FROM WHERE (Context: Table: events. Fields: SensorID, SensorType, Length)
SELECT FROM WHERE Please answer all 3 questions on this page before proceeding.
(Context: Table: TblCars. Fields: Make, Model, Year)
SELECT FROM WHERE (Context: Table: TblLibrary. Fields: Title, Author, Genre)
SELECT FROM WHERE (Context: Table: TblPlayers. Fields: PlayerName, Team)
SELECT PlayerName
FROM TblPlayers
WHERE Team = 'Harry'
(Context: Table: TblCars. Fields: CarID, Price)
SELECT FROM WHERE Please answer all 4 questions on this page before proceeding.
(Context: Table: TblPlayers. Fields: PlayerName, Score)
SELECT PlayerName
FROM TblPlayers
WHERE 'Score > 100'
(Context: Table: TblFilms. Fields: Title, Genre, Year)
SELECT FROM WHERE (Context: Table: Students. Fields: StudentID, FirstName)
SELECT
FROM
WHERE
Drag from here:
Please answer all 3 questions on this page before proceeding.
Time to write the full queries yourself! Write the complete SQL statement, including SELECT, FROM, WHERE, and a semicolon (;).
(Context: Table: TblCars. Fields: Make, Model, Price)
(Context: Table: TblLibrary. Fields: Title, Author, Genre)
(Context: Table: TblPlayers. Fields: PlayerName, Score)
(Context: Table: Results. Fields: StudentID, Subject, Grade)
Please answer all 4 questions on this page before proceeding.
This is your 1st attempt.