SQL Select statement is used to retrieve data from the database. The data is returned in form of a table called a resultset.
SQL SELECT Syntax
In SQL select statement, we specify list of columns to be fetched from database tables.
- To select specific columns from table:
Select column1, column2, columnN from table_name;
column1, column2, columnN are the column names of the table.
- To select all the columns from the database:
Select * from table_name;
Sample Table
Employee
ID | NAME | SALARY | ADDRESS | DESIGNATION | AGE |
---|---|---|---|---|---|
1 | Peter Clark | 90000.00 | Daphne Road Manukau | Manager | 36 |
2 | Alfredo Smith | 60000.00 | Pimpama Drive Rotorua | Principal Engineer | 32 |
3 | James Cook | 40500.00 | Saint-Antoine Quebec | SDE I | 27 |
4 | Hudson Stewart | 45000.00 | Stoney Creek Ontario | SDE II | 30 |
5 | Nathan Taylor | 55000.00 | Long Street, Woolston | SDE II | 31 |
Example
- The following SQL statement will select Name, Designation, Salary from Employee table
SELECT NAME, SALARY, DESIGNATION from Employee
NAME | SALARY | DESIGNATION |
---|---|---|
Peter Clark | 90000.00 | Manager |
Alfredo Smith | 60000.00 | Principal Engineer |
James Cook | 40500.00 | SDE I |
Hudson Stewart | 45000.00 | SDE II |
Nathan Taylor | 55000.00 | SDE II |
- The following SQL statement will select all fields from Employee table
SELECT * from Employee
ID | NAME | SALARY | ADDRESS | DESIGNATION | AGE |
---|---|---|---|---|---|
1 | Peter Clark | 90000.00 | Daphne Road Manukau | Manager | 36 |
2 | Alfredo Smith | 60000.00 | Pimpama Drive Rotorua | Principal Engineer | 32 |
3 | James Cook | 40500.00 | Saint-Antoine Quebec | SDE I | 27 |
4 | Hudson Stewart | 45000.00 | Stoney Creek Ontario | SDE II | 30 |
5 | Nathan Taylor | 55000.00 | Long Street, Woolston | SDE II | 31 |