This chapter explains the SELECT and SELECT * statements.
SQL SELECT statement
SELECT statement is used to select data from a table.
The results are stored in a results table (called a result set).
SQL SELECT syntax
SELECT column name FROM table name
and:
SELECT * FROM table name
Note: SQL statements are not case-sensitive. SELECT is equivalent to select.
SQL SELECT Example
To get the contents of the columns named "LastName" and "FirstName" (from the database table named "Persons"), use a SELECT statement like this:
SELECT LastName,FirstName FROM Persons
"Persons" table:
Id LastName FirstName Address City
1 Adams John Oxford Street London Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing
Result:
LastName FirstName
Adams John
Bush George
Carter Thomas
SQL SELECT * Example
Now we want to select all columns from the "Persons" table.
Please use the symbol * instead of column names, like this:
SELECT * FROM Persons
Tip: The asterisk (*) is a shortcut to select all columns.
Results:
Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing
Navigate in the result-set (result-set)
The results obtained by the SQL query program are stored in a result set. Most database software systems allow the use of programmatic functions to navigate through result sets, such as: Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, and so on.