SQL_Syntax - SQL Syntax Select...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
SQL Syntax Select SELECT "column_name" FROM "table_name"  Distinct   SELECT DISTINCT "column_name"  FROM "table_name"  Where   SELECT "column_name"  FROM "table_name"  WHERE "condition"  And/Or   SELECT "column_name"  FROM "table_name"  WHERE "simple condition"  {[AND|OR] "simple condition"}+  In   SELECT "column_name"  FROM "table_name"  WHERE "column_name" IN ('value1', 'value2', . ..)  Between   SELECT "column_name"  FROM "table_name"  WHERE "column_name" BETWEEN 'value1' AND 'value2'  Like   SELECT "column_name"  FROM "table_name"  WHERE "column_name" LIKE {PATTERN}  Order By   SELECT "column_name"  FROM "table_name"  [WHERE "condition"] ORDER BY "column_name" [ASC, DESC]  Count   SELECT COUNT("column_name")  FROM "table_name"  Group By   SELECT "column_name1", SUM("column_name2") 
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
FROM "table_name"  GROUP BY "column_name1"  Having   SELECT "column_name1", SUM("column_name2")  FROM "table_name"  GROUP BY "column_name1"  HAVING (arithematic function condition)  Create Table   CREATE TABLE "table_name" ("column 1" "data_type_for_column_1", "column 2" "data_type_for_column_2", ... )  Drop Table   DROP TABLE "table_name"  Truncate Table   TRUNCATE TABLE "table_name"  Insert Into   INSERT INTO "table_name" ("column1", "column2", . ..) VALUES ("value1", "value2", . ..)  Update UPDATE "table_name" SET "column_1" = [new value] WHERE {condition}  Delete From   DELETE FROM "table_name" WHERE {condition} 
Background image of page 2
SQL SELECT SELECT "column_name" FROM "table_name"   To illustrate the above example, assume that we have the following table:  Table  Store_Information store_name  Sales  Date  Los Angeles  $1500  Jan-05-1999  San Diego  $250  Jan-07-1999  Los Angeles  $300  Jan-08-1999  Boston  $700  Jan-08-1999  To select all the stores in this table, we key in,  SELECT store_name FROM Store_Information   Result: store_name Los Angeles San Diego Los Angeles Boston
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SQL DISTINCT The  SELECT  keyword allows us to grab all information from a column (or columns) on a table. This, of course,  necessarily mean that there will be redundencies. What if we only want to select each  DISTINCT  element? This is  easy to accomplish in SQL. All we need to do is to add  DISTINCT  after  SELECT . The syntax is as follows:  SELECT DISTINCT "column_name" FROM "table_name" For example, to select all distinct stores in Table  Store_Information Table  Store_Information store_name  Sales  Date  Los Angeles  $1500  Jan-05-1999  San Diego  $250  Jan-07-1999  Los Angeles  $300  Jan-08-1999  Boston  $700  Jan-08-1999  we key in,  SELECT DISTINCT store_name FROM Store_Information   Result:  store_name Los Angeles San Diego Boston
Background image of page 4
SQL WHERE Next, we might want to conditionally select the data from a table. For example, we may want to only retrieve stores 
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 44

SQL_Syntax - SQL Syntax Select...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online