;

SQL SELECT


In this Tutorial, we will learn how to select records from a table using SQL.

SQL SELECT Statement

The most commonly used SQL Statement is SELECT statement.

The SELECT Statement is used to fetch/retrieve or select the data from the database. The data is returned in a table like structure known as result-set.

Syntax - SELECT Statement
SELECT column1,column2...columnN
FROM tableName

Here "column1,column2..." are the fields of a tablewhose value you want to retrieve or fetch and "tableName" is the name of the table where data is stored.

Syntax - For selecting all the Columns
SELECT *
FROM tableName
Syntax - For Selecting Particular Columns
SELECT column1,column2...columnN
FROM tableName

Example:

Let us consider this table "Employee" for records.

Table Name: Employee

ID EmpName City Country Gender Salary
1 Shankar Delhi India male 25000
2 Sourabh Delhi India male 30000
3 Ranvijay Mumbai India male 15000
4 Kapil Noida India male 25000
5 Shalini Jaipur India female 18000
6 Rakesh Faridabad India male 23000
7 Akshay Mumbai India male 21000
8 Sarah New York US female 76000
9 Rocky Noida India male 28000

Here are some examples of SELECT statement:

Example - For Selecting only one Column
SELECT EmpName FROM Employee
Output 
EmpName
Shankar
Sourabh
Ranvijay
Kapil
Shalini
Rakesh
Akshay
Sarah
Rocky
Example - For Selecting Multiple Columns
SELECT ID,EmpName,City 
FROM Employee;
Output
ID EmpName City
1 Shankar Delhi
2 Sourabh Noida
3 Ranvijay Mumbai
4 Kapil Noida
5 Shalini Jaipur
6 Rakesh Faridabad
7 Akshay Mumbai
8 Sarah New York
9 Rocky Noida
Example - For Selecting All the Column
SELECT * FROM Employee
Output
ID EmpName City Country Gender Salary
1 Shankar Delhi India male 25000
2 Sourabh Delhi India male 30000
3 Ranvijay Mumbai India male 15000
4 Kapil Noida India male 25000
5 Shalini Jaipur India female 18000
6 Rakesh Faridabad India male 23000
7 Akshay Mumbai India male 21000
8 Sarah New York US female 76000
9 Rocky Noida India male 28000