SQL SELECT Statement
The SELECT statement is used to select data from a database.
SQL SELECT Statement
The SELECT statement is used to select data from a database.
The result is stored in a result table, called a result set.
SQL SELECT Syntax
SELECT column1, column2, ...
FROM table_name;
The difference between
SELECT * FROM table_name;
Parameter Description:
- column1, column2, ...: The names of the fields to select; there can be multiple fields. If no field names are specified, all fields are selected.
- table_name: The name of the table to query.
*: A wildcard indicating that all columns of the table are selected.
Demonstration Database
In this tutorial, we will use the RUNOOB sample database.
Below is the data selected from the "Websites" table:
+----+--------------+---------------------------+-------+---------+
| id | name | url | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1 | Google | https://www.google.cm/ | 1 | USA |
| 2 | 淘宝 | https://www.taobao.com/ | 13 | CN |
| 3 | Runoob Tutorial | http://www.runoob.com/ | 4689 | CN |
| 4 | 微博 | http://weibo.com/ | 20 | CN |
| 5 | Facebook | https://www.facebook.com/ | 3 | USA |
+----+--------------+---------------------------+-------+---------+
SELECT Column Example
The following SQL statement selects the "name" and "country" columns from the "Websites" table:
Example
SELECT
name
,
country
FROM
Websites
;
The output result is:

SELECT * Example
The following SQL statement selects all columns from the "Websites" table:
Example
SELECT
FROM
Websites
;
The output result is:

Navigation in a Result Set
Most database software systems allow the use of programming functions to navigate a result set, such as: Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, and so on.
Such programming functions are not covered in this tutorial. To learn about accessing data through function calls, visit our ADO tutorial or PHP Tutorial。