Difference between revisions of "SELECT Reference"
From SQLZOO
(Replaced content with "CREATE TABLE test_image ( ID NUMBER, image_filename VARCHAR2(50), image BLOB );") |
(Revert vandalisms) |
||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
| − | + | {{SELECT Ref}} | |
| − | + | 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: | |
| + | <table> | ||
| + | <tr><th>SQL</th><th>Result</th></tr> | ||
| + | <tr><td> | ||
| + | <source lang='sql'> | ||
| + | SELECT name, population | ||
| + | FROM bbc | ||
| + | WHERE region='North America' | ||
| + | </source> | ||
| + | </td><td> | ||
| + | <table class="sqlmine"><tr><th>name</th><th>population</th></tr><tr><td>Canada</td><td class="r">32000000</td></tr><tr><td>Mexico</td><td class="r">106400000</td></tr><tr><td>United States of America</td><td class="r">295000000</td></tr></table> | ||
| + | </td></tr></table> | ||
| + | *The SELECT line determines which columns to show - in this case <code>name</code> and <code>population</code>, 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]] | ||
Latest revision as of 10:11, 13 April 2013
SELECT Operations
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.
[edit] Simple SELECT
The simplest SELECT commands involve a single table:
| SQL | Result | ||||||||
|---|---|---|---|---|---|---|---|---|---|
SELECT name, population FROM bbc WHERE region='North America' |
|
- The SELECT line determines which columns to show - in this case
nameandpopulation, 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