Difference between revisions of "SELECT Reference"

From SQLZOO
Jump to: navigation, search
(Simple SELECT)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{SELECT}}
+
{{SELECT Ref}}
 
The [[SELECT]] command is used to show data from a database.
 
The [[SELECT]] command is used to show data from a database.
  
Line 21: Line 21:
 
*The WHERE clause determines which rows to show
 
*The WHERE clause determines which rows to show
 
*The SELECT statement may involve data from more than one table using a [[JOIN]] or a [[UNION]].
 
*The SELECT statement may involve data from more than one table using a [[JOIN]] or a [[UNION]].
*SELECT statements may nested - that is the output from one SELECT may be the input to another SELECT.
+
*[[SELECT within SELECT Tutorial|SELECT statements may nested]] - that is the output from one SELECT may be the input to another SELECT.
 
*The output from a SELECT may be added to another table using [[INSERT .. SELECT]]
 
*The output from a SELECT may be added to another table using [[INSERT .. SELECT]]
 +
*The select statement may aggregate values using a [[SELECT .. GROUP BY]] clause

Latest revision as of 13:31, 27 February 2015

The SELECT command is used to show data from a database.

The output from a SELECT statement is always a grid - with a number of rows and a number of columns.

Simple SELECT

The simplest SELECT commands involve a single table:

SQLResult
SELECT name, population
  FROM bbc
 WHERE region='North America'
namepopulation
Canada32000000
United States of America295000000
  • The SELECT line determines which columns to show - in this case name and population, both of which are columns of the bbc table.
  • The WHERE clause determines which rows to show
  • The SELECT statement may involve data from more than one table using a JOIN or a UNION.
  • SELECT statements may nested - that is the output from one SELECT may be the input to another SELECT.
  • The output from a SELECT may be added to another table using INSERT .. SELECT
  • The select statement may aggregate values using a SELECT .. GROUP BY clause