Computer Science · Ch 9 — Structured Query Language (SQL)
SELECT Statement
SELECT Statement
The SELECT statement is the most important command in SQL — it is how you retrieve data from a table. The result of a SELECT query is always displayed in tabular form, just like the original table.
Syntax:
SELECT attribute1, attribute2, ...
FROM table_name
WHERE condition;
Here, attribute1, attribute2, ... are the names of the columns you want to see. The FROM clause is mandatory — it tells the database which table to look in. The WHERE clause is optional; you use it only when you need to filter rows that meet a specific condition.
The FROM clause is always written together with the SELECT clause. You cannot have a SELECT without a FROM.
Selecting all columns
If you want to see every column of a table, you do not have to list them all. Instead, use the asterisk (*) as a shortcut:
SELECT * FROM table_name;
This returns the entire table — all rows and all columns.
Key points to remember
SELECTis used to retrieve data; the output is always tabular.FROMis compulsory — it names the table. …