SELECT
{{#set:Related SQL command=UPDATE |Related SQL command=DELETE |Related SQL command=INSERT |Related SQL command=FROM |Related SQL command=GROUP BY |Related SQL command=ORDER BY }}
INSERT is refers to the SQL command INSERT.
Summary
The INSERT command is used to add or insert data into a table. Syntax may vary between certain types of databases but is generally uniform across multiple vendors.
Syntax
SELECT * | <column> [, <column> [, ...]] FROM <table> [, <table> [, ...]] [ WHERE <condition> [ AND | OR <condition> [, ...] ] [ GROUP BY <column> [, <column> [, ...] ]] [ ORDER BY <column> [ ASC | DESC ] [, <column> [ ASC | DESC ] [, ...]]]]
Note: They above syntax is a simplified version to stay within the objective of this module. To view the whole syntax for a particular database consult the online documentation.
Examples
To select all the rows from table "baz" we use the star expression "*". This will select all the columns in the table and list them up.
SELECT * FROM baz
To only select rows with value "foo" in column "bar" from table "baz" do the following:
SELECT bar FROM baz WHERE bar = "foo"
To only select rows with value "foo" or value "foofoo" in column "bar" from table "baz" do the following:
SELECT bar FROM baz WHERE bar = "foo" OR bar = "foofoo"
Excersises
- Use the sample database and select various values with changing conditions [[File::/etc/passwd]].
Addtional Information
- Wikipedia on SQL SELECT
- W3Schools on SQL SELECT
- MySQL 5.0 SELECT documentation
- PostgreSQL 9.0 SELECT documentation
- SQLite SELECT documentation
http://lpic.bun.ch/index.php?title=SELECT&action=edit§ion=5