Databases & SQL
Lesson 2 of 4 9 min +75 XP

Querying with SELECT

Ask the database questions in SQL.

What you'll learn

  • Write a basic SELECT
  • Filter rows with WHERE
  • Choose specific columns
Asking the librarian

Instead of scanning every shelf, you ask the librarian 'show me all mystery novels from the 1990s.' A SELECT query is that request to the database — you describe what you want and it hands back exactly the matching rows.

SELECT what you need

SQL's SELECT statement retrieves data. You list the columns you want (or * for all), the table to read FROM, and an optional WHERE clause to filter which rows come back.

SELECT name
FROM students
WHERE grade = 12;
Lab · Build a query
  1. Choose the column to return: name.
  2. Name the table to read from: students.
  3. Filter to only 12th graders with WHERE grade = 12.

What you should see: The query returns the names of students whose grade equals 12.

Knowledge Check

+20 XP / correct

1. Which SQL clause filters which rows are returned?

2. In 'SELECT name FROM students;', what does 'students' refer to?