In this Tutorial, we will learn how to select records from a table using SQL.
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.
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.
SELECT *
FROM tableName
SELECT column1,column2...columnN
FROM tableName
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:
SELECT EmpName FROM Employee
EmpName |
Shankar |
Sourabh |
Ranvijay |
Kapil |
Shalini |
Rakesh |
Akshay |
Sarah |
Rocky |
SELECT ID,EmpName,City
FROM Employee;
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 |
SELECT * FROM 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 |