Write SELECT statements to retrieve data from a table
Choose specific columns and alias them with AS
Sort results with ORDER BY and limit them with LIMIT
Remove duplicate rows with SELECT DISTINCT
📊 SQL Query Engine
Run SQL SELECT queries against a mock students table. Try the example queries or write your own.
Table: students
id | name | grade | score | city
1 | Alice | 10 | 92 | Tulsa
2 | Bob | 11 | 78 | OKC
3 | Carlos| 10 | 85 | Tulsa
4 | Diana | 12 | 95 | Norman
5 | Ethan | 11 | 71 | OKC
6 | Fiona | 12 | 88 | Tulsa
The SELECT Statement
SELECT is the most fundamental SQL command. It reads data from one or more tables without modifying anything. Every SELECT has at minimum a column list and a FROM clause.
SELECT * FROM students — * means "all columns." Returns every column of every row.
SELECT name, score FROM students — Returns only the name and score columns.
ORDER BY, LIMIT, and DISTINCT
ORDER BY score DESC — Sort results by score, highest first. ASC (ascending, default) for lowest first.
LIMIT 3 — Return only the first 3 rows. Combine with ORDER BY to get "top N" results.
SELECT DISTINCT city FROM students — Return each city once, removing duplicates.
Column Aliases with AS
Use AS to rename a column in the result set. This is purely cosmetic — it doesn't change the actual column name in the table. Useful for making output more readable or for shortening long expression names.
SELECT name AS student_name, score AS test_score FROM students
Quick Check
1. What does SELECT * mean?
Select the first row only
Select all columns
Select only required columns
Select a random column
2. How do you sort results from highest score to lowest?
ORDER BY score ASC
ORDER BY score DESC
SORT score HIGH
WHERE score MAX
3. What does SELECT DISTINCT city FROM students return?