Select Statement is used for selecting data from a database.

Data Returned in this query is stored in a table.

Select Syntax

SELECT column1, column2, ...
FROM table_name;

Here column1,column2,…… are the column names you want to select from the table. You can select all columns at once using * instead of column names one by one.

SELECT * FROM Table_name

Sample Database

Below is a sample Employee Table

WORKER_IDFIRST_NAMELAST_NAMESALARYJOINING_DATEDEPARTMENT
001MonikaArora1000002014-02-20 09:00:00HR
002NiharikaVerma800002014-06-11 09:00:00Admin
003VishalSinghal3000002014-02-20 09:00:00HR
004AmitabhSingh5000002014-02-20 09:00:00Admin
005VivekBhati5000002014-06-11 09:00:00Admin
006VipulDiwan2000002014-06-11 09:00:00Account
007SatishKumar750002014-01-20 09:00:00Account
008GeetikaChauhan900002014-04-11 09:00:00Admin

SELECT Column Example

The following SQL statement selects the “FIRST_NAME” and “SALARY” columns from the “EMPLOYEE” table:

SELECT FIRST_NAME, SALARY FROM EMPLOYEE

SELECT * Example

The following SQL statement selects all the columns from the “Employee” table:

SELECT * FROM EMPLOYEE

The SQL SELECT DISTINCT Statement

Select Distinct Statement is used for selecting only distinct values

Sometimes in table there are duplicate values but we want to return only distinct values for those columns here we can use Select Distinct Statement.

SELECT DISTINCT column1, column2, ...
FROM table_name;
SELECT DISTINCT DEPARTMENT FROM EMPLOYEE;
SELECT Count(*) AS DistinctDepartments
FROM (SELECT DISTINCT DEPARTMENT FROM EMPLOYEE);

For more SQL related tutorials Visit Us Geekycodes . Follow us on Instagram

Leave a Reply