Your First SQL Query
You'll learn how to write a basic SELECT statement to retrieve data from a database table—the foundation of working with structured data.
The Core Idea
A SQL query is like asking a question to your database. The simplest and most common query uses the SELECT statement to pull specific information from a table. Think of it like pointing at a filing cabinet drawer (the table) and saying "show me what's inside."
Your First SELECT Statement
The basic structure is:
SELECT column_name FROM table_name;
For example, if you have a table called customers with columns like name, email, and age, you could write:
SELECT name FROM customers;
This retrieves all customer names from the table.
Selecting Multiple Columns
Want more than one piece of information? List columns separated by commas:
SELECT name, email FROM customers;
The Asterisk Shortcut
To retrieve everything from a table, use *:
SELECT * FROM customers;
This is like saying "show me all columns for all rows." It's great for exploring data, though in production you'd typically select only what you need.
Reading the Results
When you execute (run) your query, the DBMS returns a result set—a temporary table showing the requested data. Each row represents one record, and each column shows the values you selected.
Key Takeaway: The SELECT statement is your primary tool for retrieving data from tables—specify which columns you want and which table to get them from, and SQL returns the matching data.