SELECT Statement
SELECT is the most fundamental SQL statement — it retrieves data from one or more tables. Every SQL query you write begins here. Understanding SELECT thoroughly is the foundation for all advanced SQL.
Core Concepts
- SELECT retrieves data — it never modifies the database
- SELECT * gets all columns — avoid in production, use specific columns
- SQL execution order: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT
- Written order: SELECT → FROM → WHERE → ORDER BY → LIMIT
- Semicolon (;) terminates every SQL statement
- SQL keywords are case-insensitive: SELECT = select = Select
SELECT in Action
-- Select all columns (all data from users)
SELECT * FROM users;
-- Result:
-- id | name | email | created_at
-- 1 | John Doe | john@example.com | 2024-01-15 09:00:00
-- 2 | Alice Smith| alice@example.com | 2024-01-16 10:00:00
-- 3 | Bob Lee | bob@example.com | 2024-01-17 11:00:00
-- Select specific columns only (best practice)
SELECT name, email FROM users;
-- Select with a computed column
SELECT name, price, price * 0.9 AS discounted_price FROM products;
-- Select literal values (no table needed)
SELECT 'Hello World';
SELECT 42 + 8 AS result;
SELECT NOW() AS current_time;Quick Quiz
Tip
Tip
Practice SELECT Statement in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
SQL doesn't run top-to-bottom. FROM executes first.
Common Mistake
Warning
A common mistake with SELECT Statement is skipping edge case testing — empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready sql code.
Practice Task
Note
Practice Task — (1) Write a working example of SELECT Statement from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Key Takeaways
- SELECT is the most fundamental SQL statement — it retrieves data from one or more tables.
- SELECT retrieves data — it never modifies the database
- SELECT * gets all columns — avoid in production, use specific columns
- SQL execution order: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT