SQL Tutorial

SQL SELECT Statement

This tutorial shows you how to select data from database tables using the SQL SELECT statement. Here is the syntax:

SELECT [DISTINCT] column_name|*|expression
       AS column_alias
FROM  [table_or_view_name]

The SQL SELECT statement allows you to select values in the columns, literal values, or expressions. you can select from single or multiple columns. Here is an example of selecting name column of employees table:

SELECT name FROM employees

To select all columns you can list all column' names or using * notation like this:

SELECT id, name, salary  FROM employees

is same as

SELECT * FROM employees

With DISTINCT keyword, SQL SELECT statement also provides an easy way to eliminate any duplicate values from the final result set. Here is an example of selecting distinct salary from employees table:

SELECT DISTINCT salary
FROM employees

It will display all distinct salaries values from employee table so you know how many salary level of employees.

With SQL SELECT statement you are not limited to select data from database tables. The SQL SELECT statement is not only involved with database table. You can also select literals, functions, and calculated columns. Here are examples:

in MySQL you can get the current date time by execute:

SELECT NOW() AS current_datetime

You can use max and min function to identity salary range of your company by execute:

SELECT MAX(salary) AS max_salary,		   
 MIN(salary) AS min_salary 
FROM employees

To select data from more than two table you can read it here in using SQL JOIN

To use search conditions for SQL SELECT statement you can use SQL WHERE clause