SQL SELECT statement
The SELECT statement is used to select data from the database.
The results are stored in a result table, called a result set.
SQL SELECT syntax
SELECT column_name,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"), please Use a SELECT statement like this:
SELECT LastName,FirstName FROM Persons
"Persons" table:
LastName | FirstName | Address | City | |
---|---|---|---|---|
Adams | John | Oxford Street | London | |
Bush | George | Fifth Avenue | New York | |
Carter | Thomas | Changan Street | Beijing |
FirstName | |
---|---|
John | |
George | |
Thomas |
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.
Result:
FirstName | Address | City | 1 | |
---|---|---|---|---|
John | Oxford Street | London | 2 | |
George | Fifth Avenue | New York | 3 | |
Thomas | Changan Street | Beijing |
Navigating in the 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 within result sets, such as: Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, and so on.
Recommended: "SQL Video Tutorial
"The above is the detailed content of Select statement in sql language. For more information, please follow other related articles on the PHP Chinese website!