SQL SELECT
The SELECT statement is used to select data from the database.
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;
FROM table_name;
AND
SELECT * FROM table_name;
DEMO DATABASE
IN In this tutorial, we will use the PHP sample database.
The following is the data selected from the "Websites" table:
+----+------------ --+--------------------------+-------+---------+
| id | name | url | alexa | country |
+----+-------------+------------- --------------+-------+---------+
| 1 | Google | https://www.google.cm / | 1 | USA |
| 2 | Taobao | https://www.taobao.com/ | 13 | CN |
| 3 | php Chinese website | http://www.php.cn/ | 4689 | CN |
| 4 | Weibo | http://weibo.com/ | 20 | CN |
| 5 | Facebook | https://www.facebook.com/ | 3 | USA |
+----+-------------+--------------------------- +-------+---------+
| id | name | url | alexa | country |
+----+-------------+------------- --------------+-------+---------+
| 1 | Google | https://www.google.cm / | 1 | USA |
| 2 | Taobao | https://www.taobao.com/ | 13 | CN |
| 3 | php Chinese website | http://www.php.cn/ | 4689 | CN |
| 4 | Weibo | http://weibo.com/ | 20 | CN |
| 5 | Facebook | https://www.facebook.com/ | 3 | USA |
+----+-------------+--------------------------- +-------+---------+
##SELECT Column ExampleThe following SQL statement selects the "name" and "country" columns from the "Websites" table:
ExampleSELECT name,country FROM Websites ;The output result is:
##SELECT * ExampleThe following SQL Statement to select all columns from the "Websites" table:
ExampleSELECT * FROM Websites;
The output result is:
The following command executes the output result:
Navigation in the result set
Most database software systems allow the use of programmatic functions to navigate within the result set, such as: Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, etc.
Programming functions like these are not covered in this tutorial. To learn about accessing data through function calls, visit our ADO tutorial or our PHP tutorial.