SQL SELECT Statement
The SQL SELECT statement is the most frequently used SQL query or command. It is used to fetch or retrieve all data (columns and rows) or partial (specific columns) data from a database table.
The SQL SELECT command returns matched query data in the form of table (rows and columns).
These tables are called result set or result table.
Related Links
Sql Select Query Syntax
The below syntax is used to select specific column(s) from the specific table.
SELECT
column_name1, column_name2, column_nameN
FROM table_name;
The below syntax is used to select all column(s) from the specific table.
SELECT * FROM table_name;
Note:- You can write all SQL statements in a single line or multiple line.
- SELECT - The SELECT command specifies the list of columns that are retrieved from the table.
- FROM - The FROM command specifies from where data should be retrieved.
Sample Database Table - Books
BookID | BookName | BookPrice |
---|---|---|
1 | Easy Oracle PL/SQL Programming | 195 |
2 | Professional MySql | 150 |
3 | Foundations Of Sql Server 2008 | 145 |
4 | Making Sense Of SQL | 165 |
SELECT Specific Column Example
The following SQL SELECT statement selects the "BookName" and "BookPrice" columns from the "Books" table:
SELECT
BookName, BookPrice
FROM Books;
Note: Column names are separated by commas(,).
The result of above query is:
BookName | BookPrice |
---|---|
Easy Oracle PL/SQL Programming | 195 |
Professional MySql | 150 |
Foundations Of Sql Server 2008 | 145 |
Making Sense Of SQL | 165 |
SELECT * Example
The following SQL SELECT statement selects all the column names or fields of "Books" table:
SELECT * FROM Books;
Note: '*' is a special characters, which is used to select all columns from the table.
The result of above query is:
BookID | BookName | BookPrice |
---|---|---|
1 | Easy Oracle PL/SQL Programming | 195 |
2 | Professional MySql | 150 |
3 | Foundations Of Sql Server 2008 | 145 |
4 | Making Sense Of SQL | 165 |
Related Links