In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an...

download In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Reference for Someone to Learn SQL. for Detailed Explanations of Each SQL Syntax,

of 12

Transcript of In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an...

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    1/12

    In this page, we list the SQL syntax for each of the SQL commands in this tutorial, making this aneasy reference for someone to learn SQL. For detailed explanations of each SQL syntax, please goto the individual section by clicking on the keyword.

    The purpose of this page is to have a quick reference page for SQL syntax, so you can learn SQLmore quickly. Bookmark this page now by pressing Control-D so you can have this syntax page

    handy.

    Select StatementSELECT "column_name" FROM "table_name"

    DistinctSELECT DISTINCT "column_name"FROM "table_name"

    WhereSELECT "column_name"FROM "table_name"WHERE "condition"

    And/Or SELECT "column_name"FROM "table_name"WHERE "simple condition"{[AND|OR] "simple condition"}+

    InSELECT "column_name"FROM "table_name"WHERE "column_name" IN ('value1', 'value2', ...)

    BetweenSELECT "column_name"FROM "table_name"WHERE "column_name" BETWEEN 'value1' AND 'value2'

    LikeSELECT "column_name"

    FROM "table_name"WHERE "column_name" LIKE {PATTERN}

    Order BySELECT "column_name"FROM "table_name"[WHERE "condition"]ORDER BY "column_name" [ASC, DESC]

    CountSELECT COUNT("column_name")

    FROM "table_name"

    Group By

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    2/12

    SELECT "column_name1", SUM("column_name2")FROM "table_name"GROUP BY "column_name1"

    HavingSELECT "column_name1", SUM("column_name2")

    FROM "table_name"GROUP BY "column_name1"HAVING (arithematic function condition)

    Create Table StatementCREATE TABLE "table_name"("column 1" "data_type_for_column_1","column 2" "data_type_for_column_2",... )

    Drop Table StatementDROP TABLE "table_name"

    Truncate Table StatementTRUNCATE TABLE "table_name"

    Insert Into StatementINSERT INTO "table_name" ("column1", "column2", ...)VALUES ("value1", "value2", ...)

    Update StatementUPDATE "table_name"SET "column_1" = [new value]WHERE {condition}

    Delete From StatementDELETE FROM "table_name"WHERE {condition}

    Link to this page: If you find this page useful, we encourage you to link to this page. Simply copyand paste the code below to your website, blog, or profile.

    SQL SyntaxCopyright 2010 1keydata.com. All Rights Reserved. Privacy Policy Post to DeliciousBookmark to Google Share on Twitter Bookmark to Mister Wong Share on Facebook Stumble ThisSite

    SQL SELECT

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    3/12

    SQL DISTINCTSQL WHERESQL AND OR SQL INSQL BETWEENSQL Wildcard

    SQL LIKESQL ORDER BYSQL FunctionsSQL AverageSQL COUNTSQL MAXSQL MINSQL SUMSQL GROUP BYSQL HAVINGSQL ALIASSQL ASSQL JOINSQL OUTER JOINSQL SELECT UNIQUESQL CONCATENATESQL SUBSTRINGSQL TRIMSQL LENGTHSQL REPLACESQL DATEADDSQL DATEDIFFSQL DATEPARTSQL GETDATESQL SYSDATE

    SQL CREATE TABLESQL CONSTRAINTSQL NOT NULLSQL DEFAULTSQL UNIQUESQL CHECK

    SQL PRIMARY KEYSQL FOREIGN KEYSQL ViewSQL CREATE VIEWSQL IndexSQL CREATE INDEXSQL ALTER TABLESQL DROP TABLESQL TRUNCATE TABLESQL USESQL INSERT INTO

    SQL UPDATESQL DELETE FROM

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    4/12

    SQL Jobs

    Site MapResources

    CSS Tutorial

    PHP Tutorial

    Data Warehousing & Business Intelligence

    View this site in:Traditional Chinese Version SQLGerman Version SQL-TutorialFrench Version Tutoriel SQLSpanish Version Tutorial de SQLJapanese Version SQL

    Korean Version SQL

    Simplified Chinese Version SQL

    SQL HOME

    SQL IntroSQL SyntaxSQL SelectSQL DistinctSQL WhereSQL And & Or SQL Order BySQL InsertSQL UpdateSQL Delete

    SQL DemoSQL Try It

    SQL AdvancedSQL TopSQL LikeSQL WildcardsSQL InSQL BetweenSQL AliasSQL JoinsSQL Inner JoinSQL Left JoinSQL Right Join

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    5/12

    SQL Full JoinSQL UnionSQL Select IntoSQL Create DBSQL Create TableSQL Constraints

    SQL Not NullSQL UniqueSQL Primary KeySQL Foreign KeySQL Check SQL DefaultSQL Create IndexSQL DropSQL Alter SQL IncrementSQL ViewsSQL DatesSQL NullsSQL isnull()SQL Data Types

    SQL FunctionsSQL FunctionsSQL avg()SQL count()SQL first()SQL last()SQL max()SQL min()SQL sum()SQL Group BySQL HavingSQL ucase()SQL lcase()SQL mid()SQL len()SQL round()

    SQL now()SQL format()

    SQL Quick Ref SQL HostingSQL Summary

    SQL QuizSQL Quiz

    SQL WHERE Clause

    Previous Next Chapter

    The WHERE clause is used to filter records.

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    6/12

    The WHERE Clause

    The WHERE clause is used to extract only those records that fulfill a specified criterion.SQL WHERE SyntaxSELECT column_name(s)FROM table_name

    WHERE column_name operator value

    WHERE Clause Example

    The "Persons" table:P_Id LastName FirstName Address City1 Hansen Ola Timoteivn 10 Sandnes2 Svendson Tove Borgvn 23 Sandnes3 Pettersen Kari Storgt 20 Stavanger

    Now we want to select only the persons living in the city "Sandnes" from the table above.

    We use the following SELECT statement:SELECT * FROM PersonsWHERE City='Sandnes'

    The result-set will look like this:P_Id LastName FirstName Address City1 Hansen Ola Timoteivn 10 Sandnes2 Svendson Tove Borgvn 23 Sandnes

    Quotes Around Text Fields

    SQL uses single quotes around text values (most database systems will also accept double quotes).

    Although, numeric values should not be enclosed in quotes.

    For text values:This is correct:

    SELECT * FROM Persons WHERE FirstName='Tove'

    This is wrong:SELECT * FROM Persons WHERE FirstName=Tove

    For numeric values:This is correct:

    SELECT * FROM Persons WHERE Year=1965

    This is wrong:

    SELECT * FROM Persons WHERE Year='1965'

    Operators Allowed in the WHERE Clause

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    7/12

    With the WHERE clause, the following operators can be used:Operator Description= Equal Not equal> Greater than

    < Less than>= Greater than or equal

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    8/12

    Recommended Oracle books

    Copyright SS64.com 1999-2010

    http://ss64.com/links/oralinks.htmlhttp://ss64.com/http://ss64.com/http://ss64.com/ora/syntax.html#http://ss64.com/links/oralinks.htmlhttp://ss64.com/
  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    9/12

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    10/12

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    11/12

  • 8/9/2019 In This Page, We List the SQL Syntax for Each of the SQL Commands in This Tutorial, Making This an Easy Referen

    12/12