SQL SELECT statement

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

IDNAMESALARYADDRESSDESIGNATIONAGE
1Peter Clark90000.00Daphne Road ManukauManager36
2Alfredo Smith60000.00Pimpama Drive RotoruaPrincipal Engineer32
3James Cook40500.00Saint-Antoine QuebecSDE I27
4Hudson Stewart45000.00Stoney Creek OntarioSDE II30
5Nathan Taylor55000.00Long Street, WoolstonSDE II31

Example

  • The following SQL statement will select Name, Designation, Salary from Employee table
SELECT NAME, SALARY, DESIGNATION from Employee
NAMESALARYDESIGNATION
Peter Clark90000.00Manager
Alfredo Smith60000.00Principal Engineer
James Cook40500.00SDE I
Hudson Stewart45000.00SDE II
Nathan Taylor55000.00SDE II

  • The following SQL statement will select all fields from Employee table
SELECT * from Employee
IDNAMESALARYADDRESSDESIGNATIONAGE
1Peter Clark90000.00Daphne Road ManukauManager36
2Alfredo Smith60000.00Pimpama Drive RotoruaPrincipal Engineer32
3James Cook40500.00Saint-Antoine QuebecSDE I27
4Hudson Stewart45000.00Stoney Creek OntarioSDE II30
5Nathan Taylor55000.00Long Street, WoolstonSDE II31
Liked the article? Share this on

Leave a Comment

Your email address will not be published.