The SQL SELECT Statement
The SELECT statement is used to select data from a table. The tabular result is stored in a result table (called the result-set).
Syntax
SELECT column_name(s)
FROM table_name
Note: SQL statements are not case sensitive. SELECT is the same as select.
SQL SELECT Example
To select the content of columns named "LastName" and "FirstName", from the database table called "Persons", use a SELECT statement like this:
SELECT LastName,FirstName FROM Persons
The database table "Persons":
LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger
The result
LastName FirstName
Hansen Ola
Svendson Tove
Pettersen Kari
Select All Columns
To select all columns from the "Persons" table, use a * symbol instead of column names, like this:
SELECT * FROM Persons
Result
LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger