SQL Select Statement
Select statement is query to fetch single or set of records from the data set. Select statement may consists of number of other important SQL clauses such as Distinct, Where, Limit, Group By or Order By. In select statement we can also use aggregative functions.
SELECT Statement Syntax
The fundamental and commonly used examples syntax of select statement is.
SELECT * | list_of_columns FROM table
Here select is the SQL clause keyword, after this we can select all columns of provided table for this purpose we will use * or provide list of specific columns. Here list of columns will be separated by comma's. After list of columns table name is provided that is unique in database.
Raw Database Table Example
For demonstrate examples of select statement or even other SQL clauses we are required a database schema. The following database table will be used for all such kind of queries.
Table name is employee from industry database.
Important Note!.The above defined table is temporary and created using random values. This record does not belong to any person in real life. These all four records will be used only for SQL queries testing purpose.
How to Select Distinct Columns
Sometimes there are duplicate column values exist in particular field of database table. If we want to retrieve only unique values means each value only one time. This is called distinct selection. In SQL Distinct keyword is used before column identifier.
SELECT DISTINCT column_name FROM table_name
SELECT DISTINCT `name`,`dob` FROM employee
The result of the above defined query will include single names record of each person. In databse table there are two persons having the same name "jack", but as the DISTINCT keyword is used so that the query will fetch and display only first occurrance of record having jack name.