Difference between revisions of "SELECT"

From braindump
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 45: Line 45:
# Use the [[sample database]] and select various values with changing conditions [[File::/etc/passwd]].
# Use the [[sample database]] and select various values with changing conditions [[File::/etc/passwd]].


== Addtional Information ==
== Additional Information ==
* [http://en.wikipedia.org/wiki/Select_%28SQL%29 Wikipedia on SQL SELECT]
* [http://en.wikipedia.org/wiki/Select_%28SQL%29 Wikipedia on SQL SELECT]
* [http://www.w3schools.com/SQL/sql_select.asp W3Schools on SQL SELECT]
* [http://www.w3schools.com/SQL/sql_select.asp W3Schools on SQL 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&section=5

Latest revision as of 02:51, 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

  1. Use the sample database and select various values with changing conditions [[File::/etc/passwd]].

Additional Information