Your First SELECT Query
SELECT is the most important SQL command. It retrieves data from a table. Learn SELECT, FROM, WHERE, and ORDER BY. This is a foundational concept in database management and queries that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world SQL experience. Take your time with each section and practice the examples
20 min•By Priygop Team•Last updated: Feb 2026
The SELECT Statement
SELECT is used to retrieve data from a database table. It is the most frequently used SQL command. The basic syntax is: SELECT columns FROM table. Use * to select all columns. Use WHERE to filter rows. Use ORDER BY to sort results.
SELECT Syntax
- SELECT * FROM table — Get all columns and all rows
- SELECT col1, col2 FROM table — Get specific columns
- WHERE condition — Filter rows (like an if statement)
- ORDER BY column ASC/DESC — Sort results
- LIMIT n — Return only first n rows
- DISTINCT — Remove duplicate values
- SQL keywords are NOT case-sensitive (select = SELECT)
SELECT Examples
Example
-- Get all students
SELECT * FROM students;
-- Get only name and age columns
SELECT name, age FROM students;
-- Get students from Mumbai only
SELECT * FROM students
WHERE city = 'Mumbai';
-- Get students older than 20, sorted by age
SELECT name, age FROM students
WHERE age > 20
ORDER BY age ASC;
-- Get only the first 2 results
SELECT * FROM students
LIMIT 2;
-- Get unique cities (no duplicates)
SELECT DISTINCT city FROM students;Try It Yourself: SELECT Queries
Try It Yourself: SELECT QueriesJavaScript
JavaScript Editor
✓ ValidTab = 2 spaces
JavaScript|26 lines|1087 chars|✓ Valid syntax
UTF-8