Difference between revisions of "SELECT"

From braindump
Jump to navigation Jump to search
Line 44: Line 44:
== Excersises ==
== Excersises ==
# 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 ==
* [http://en.wikipedia.org/wiki/Select_%28SQL%29 Wikipedia on SQL SELECT]
* [http://dev.mysql.com/doc/refman/5.0/en/select.html MySQL 5.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]

Revision as of 02:34, 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]].

Addtional Information