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 result is stored in a result table, called the result set.
SQL SELECT syntax
SELECT column_name , column_name
FROM table_name ;
FROM table_name ;
versus
SELECT * FROM table_name ;
Demo database
In this tutorial, we will use the RUNOOB 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 | rookie tutorial | http://www.runoob.com/ | 4689 | CN | | 4 | microblogging | http://weibo.com/ | 20 | CN | 5 | Facebook | https://www.facebook.com/ | 3 | USA | + ---- + -------------- + --------------------------- + - ------ + --------- +
SELECT Column instance
The following SQL statement selects the "name" and "country" columns from the "Websites" table:
Examples
SELECT Name , country FROM Websites ;
The output is:
SELECT * instance
The following SQL statement selects all columns from the "Websites" table:
Examples
SELECT * FROM Websites ;
The output is:
Results of the centralized navigation
Most database software systems allow the use of programming functions to navigate in the result set, such as: Move-To-First-Record, Get-Record-Content, Move-To-Next-Record, and so on.
EmoticonEmoticon