Lesson 1 of 10
Your first query
- 9 min
- 4 checks
- 3 hints
- Go to task
Goal
SELECT and WHERE
Explanation
In SQL you don't tell the database how to search. You tell it what you want, and it works out how to find it on its own.
SELECT names the columns you want, FROM names the table to read from, and WHERE sets the condition the rows have to meet:
SELECT name FROM students WHERE score > 80;
Put text values in single quotes, like 'Riyadh'. In SQL, double quotes are for column names, not values, and mixing them up is the most common mistake people make when they come to SQL from another programming language.
Your task
Show only the name and score of the students from Riyadh.
Checks
4 checks- Only two columns: name and score
- Three rows
- Every student is from Riyadh
- Scores match the table
Tables in this lesson
CREATE TABLE students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
city TEXT NOT NULL,
score INTEGER NOT NULL
);
INSERT INTO students (name, city, score) VALUES
('Layan', 'Riyadh', 88),
('Khalid', 'Jeddah', 95),
('Reem', 'Riyadh', 72),
('Sara', 'Dammam', 91),
('Fahad', 'Jeddah', 64),
('Noura', 'Riyadh', 79);