The SELECT statement is used to select data from a table. The tabular result is stored in a result table (called the result-set).
SELECT column_name(s) FROM table_name
To select the columns named LastName
and FirstName
, use a SELECT statement like this:
SELECT LastName, FirstName FROM Person
Table Person:
+----------+-----------+--------+-------------+ | LastName | FirstName | Number | DateOfBirth | +----------+-----------+--------+-------------+ | Smith | John | 10 | 1980-01-01 | +----------+-----------+--------+-------------+ | Doe | John | 3 | 1981-12-25 | +----------+-----------+--------+-------------+
Result Set:
+----------+-----------+ | LastName | FirstName | +----------+-----------+ | Smith | John | +----------+-----------+ | Doe | John | +----------+-----------+
The order of the columns in the result is the same as the order of the columns in the query.
To select all columns from the Person
table, use a *
symbol instead of column names, like this:
SELECT * FROM Person
Result Set:
+----------+-----------+--------+-------------+ | LastName | FirstName | Number | DateOfBirth | +----------+-----------+--------+-------------+ | Smith | John | 10 | 1980-01-01 | +----------+-----------+--------+-------------+ | Doe | John | 3 | 1981-12-25 | +----------+-----------+--------+-------------+