1.2 — Your First SELECT Statement
What You'll Learn
- How to view data from a database table using SQL
- The basic structure of a SQL
SELECT
statement - How this compares to viewing data in Excel
From Excel to SQL: Viewing Your Data
In Excel, you simply open a worksheet to see all your data. In SQL, you use a SELECT
statement to do the same thing.
Excel:
Open the "Sales" worksheet to see all rows and columns.
SQL:
Use a query to view all data from the sales
table:
sql
SELECT * FROM sales;
SELECT
tells the database you want to view data.*
means "all columns".FROM sales
specifies the table.
Example Table
SaleDate | Product | Amount |
---|---|---|
2024-05-01 | Apples | 120 |
2024-05-01 | Oranges | 80 |
The SQL above will return all rows and columns from the sales
table—just like opening the worksheet in Excel.
Key Points
SELECT * FROM table;
is the simplest way to view all data.- This is similar to opening a worksheet in Excel.
- You can replace
*
with specific column names to view only those columns (covered in the next lesson).
Next Steps
In the next lesson, you'll learn how to select only the columns you need—just like hiding or showing columns in Excel.