What is SELECT?
SELECT retrieves data from a table. It's the most used SQL command - you'll use it every time you want to see data.
The Syntax
SELECT columns FROM table_name;Select All Columns
Use * to get everything:
SELECT * FROM students;Result: (see table below)
SELECT * FROM students - All Columns
| id | name | age | grade |
|---|---|---|---|
| 1 | Alice | 20 | A |
| 2 | Bob | 22 | B |
| 3 | Charlie | 21 | A |
3 rows
Select Specific Columns
Choose only what you need:
SELECT name, age FROM students;Result: (see specific columns table below)
SELECT name, age - Specific Columns
| name | age |
|---|---|
| Alice | 20 |
| Bob | 22 |
| Charlie | 21 |
3 rows
SELECT DISTINCT
Get unique values only (no duplicates):
SELECT DISTINCT grade FROM students;Returns: A, B, C (each grade only once)
Column Aliases (AS)
Rename columns in your results:
SELECT name AS student_name FROM students;How SELECT Works (Step by Step)
Step 1: Write SELECT
Step 2: List columns (or * for all)
Step 3: Write FROM
Step 4: Specify table name
Step 5: Add semicolon ;
SELECT name, age -- Step 1 & 2
FROM students; -- Step 3, 4 & 5Quick Reference
SELECT *- All columnsSELECT col1, col2- Specific columnsSELECT DISTINCT col- Unique values onlySELECT col AS alias- Rename column
Tip: Always select only the columns you need - it's faster than using
*!
Try SELECT *
Get all columns from the students table
SQL Editor
Loading...
Output
Click "Run Query" to see results