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_ID | FIRST_NAME | LAST_NAME | SALARY | JOINING_DATE | DEPARTMENT |
001 | Monika | Arora | 100000 | 2014-02-20 09:00:00 | HR |
002 | Niharika | Verma | 80000 | 2014-06-11 09:00:00 | Admin |
003 | Vishal | Singhal | 300000 | 2014-02-20 09:00:00 | HR |
004 | Amitabh | Singh | 500000 | 2014-02-20 09:00:00 | Admin |
005 | Vivek | Bhati | 500000 | 2014-06-11 09:00:00 | Admin |
006 | Vipul | Diwan | 200000 | 2014-06-11 09:00:00 | Account |
007 | Satish | Kumar | 75000 | 2014-01-20 09:00:00 | Account |
008 | Geetika | Chauhan | 90000 | 2014-04-11 09:00:00 | Admin |
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