SELECT

From braindump
Revision as of 03:52, 18 January 2011 by Uroesch (talk | contribs) (Created page with "Category: Module 105.3 Category: SQL {{#set:Related SQL command=UPDATE |Related SQL command=DELETE |Related SQL command=INSERT |Related SQL command=FROM |Related SQL comm...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

{{#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 ] [, ...]]]]

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]].