SQL SELECT Statement

This chapter explains the SELECT and SELECT * statements.

SQL SELECT Statement

SELECT statement is used to select data from a table.

The result is stored in a result table (referred to as a result set).

SQL SELECT Syntax

SELECT Column Name FROM Table Name

and

SELECT * FROM Table Name

Note:SQL statements are case-insensitive. SELECT is equivalent to select.

SQL SELECT Example

To get the content of 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
2 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.

Use the symbol * to replace the column name, like this:

SELECT * FROM Persons

Tip:The asterisk (*) is a shortcut for selecting all columns.

Result:

Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing

Navigating in the Result Set (result-set)

The results obtained from SQL query programs are stored in a result set. Most database software systems allow the use of programming functions to navigate within a result set, such as: Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, etc.

Programming functions similar to these are not covered in this tutorial. If you want to learn how to access data through function calls, please visit our ADO Tutorial And PHP Tutorial.