SQL SELECT Statement


The SELECT statement is used to select data from a database. The result is stored in a result table (called the result-set).

SELECT Syntax
The SELECT statement is complicated. One of the simplified syntax of the SELECT statement is given below:
SELECT Semantics
Executing a SELECT command is basically done in three steps implicitly, which makes SQL more concise compared to traditional programming languages:
  1. Derive a Cartesian product of the operand tables indicated in the FROM clause, where the Cartesian product of two sets A and B, denoted A × B, is the set of all ordered pairs (a, b) where a is in A and b is in B.

  2. Based on this intermediate result, evaluate the conditions stated in the WHERE clause.

  3. Project the result from Step 2 onto the attributes indicated in the SELECT clause; DISTINCT may be added to avoid duplicate tuples in the result.


Demonstration
Below is an SQL test area from W3Schools, which uses the well-known Northwind sample database. The tables here are for read only because of the problem of embedding the scripts. For a fully working example, check this by using Chrome.

SQL Statement:

Edit the SQL statement and click     to see the result, or  

Result:
The Database includes:
The Database includes:

TablenameRecord
Customers91
Categories8
Employees10
OrderDetails518
Orders196
Products77
Shippers3
Suppliers29