Difference between revisions of "SELECT"
Line 51: | Line 51: | ||
* [http://www.postgresql.org/docs/9.0/static/sql-select.html PostgreSQL 9.0 SELECT documentation] |
* [http://www.postgresql.org/docs/9.0/static/sql-select.html PostgreSQL 9.0 SELECT documentation] |
||
* [http://www.sqlite.org/lang_select.html SQLite SELECT documentation] |
* [http://www.sqlite.org/lang_select.html SQLite SELECT documentation] |
||
http://lpic.bun.ch/index.php?title=SELECT&action=edit§ion=5 |
Revision as of 02:46, 19 January 2011
{{#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]].