SELECT Statement Fundamentals
You'll learn how to retrieve data from database tables using the SELECT statement, the workhorse of SQL queries.
What is SELECT?
The SELECT statement is SQL's primary tool for reading data from a database. Think of it like asking the database a question: "Show me information from this table." Unlike operations that modify data, SELECT simply retrieves and displays what's already stored.
Retrieving Specific Columns
To get data from particular columns, list them after the SELECT keyword:
SELECT first_name, last_name FROM employees;
This query asks the database: "Give me just the first_name and last_name columns from the employees table." You'll see only those two pieces of information for each row.
You can select one column, multiple columns (separated by commas), or change the order:
SELECT email FROM users;
SELECT product_name, price, quantity FROM inventory;
Retrieving All Columns with Asterisk (*)
When you want everything a table has to offer, use the asterisk notation:
SELECT * FROM customers;
The * is shorthand for "all columns." It's like saying "show me the complete picture." This is convenient for exploration, but in production code, explicitly naming columns is often better for clarity and performance.
Analogy
Think of a table as a spreadsheet. SELECT lets you choose which columns to view—like hiding certain columns in Excel. Naming columns is like selecting "Column A and Column D only," while SELECT * is like viewing the entire spreadsheet.
Key Takeaway: The SELECT statement retrieves data from tables—list specific column names to get targeted data, or use SELECT * to retrieve all columns at once.