Lesson 1 of 10

Your first query

Goal

SELECT and WHERE

01

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.

02

Your task

Show only the name and score of the students from Riyadh.

Checks

4 checks
  1. Only two columns: name and score
  2. Three rows
  3. Every student is from Riyadh
  4. 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);
03

Hints

0/3
Track lessons0 of 10 done
query.sql
OutputSQLite (sql.js)

Loading SQLite.

–/4

Checks start once the environment is ready.

4 checks listed under “Your task”.

Track lessons0 of 10 done