You are on page 1of 12

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, please go
to 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 SQL
more quickly. Bookmark this page now by pressing Control-D so you can have this syntax page
handy.

Select Statement
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")
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 Statement


CREATE TABLE "table_name"
("column 1" "data_type_for_column_1",
"column 2" "data_type_for_column_2",
... )

Drop Table Statement


DROP TABLE "table_name"

Truncate Table Statement


TRUNCATE TABLE "table_name"

Insert Into Statement


INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...)

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

Delete From Statement


DELETE FROM "table_name"
WHERE {condition}

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

<a href="http://www.1keydata.com/sql/sql-syntax.html">SQL Syntax</a>

Copyright 2010 1keydata.com. All Rights Reserved. Privacy Policy Post to Delicious
Bookmark to Google Share on Twitter Bookmark to Mister Wong Share on Facebook Stumble This
Site

SQL SELECT
SQL DISTINCT
SQL WHERE
SQL AND OR
SQL IN
SQL BETWEEN
SQL Wildcard
SQL LIKE
SQL ORDER BY
SQL Functions
SQL Average
SQL COUNT
SQL MAX
SQL MIN
SQL SUM
SQL GROUP BY
SQL HAVING
SQL ALIAS
SQL AS
SQL JOIN
SQL OUTER JOIN
SQL SELECT UNIQUE
SQL CONCATENATE
SQL SUBSTRING
SQL TRIM
SQL LENGTH
SQL REPLACE
SQL DATEADD
SQL DATEDIFF
SQL DATEPART
SQL GETDATE
SQL SYSDATE

SQL CREATE TABLE


SQL CONSTRAINT
SQL NOT NULL
SQL DEFAULT
SQL UNIQUE
SQL CHECK
SQL PRIMARY KEY
SQL FOREIGN KEY
SQL View
SQL CREATE VIEW
SQL Index
SQL CREATE INDEX
SQL ALTER TABLE
SQL DROP TABLE
SQL TRUNCATE TABLE
SQL USE
SQL INSERT INTO
SQL UPDATE
SQL DELETE FROM
SQL Jobs

Site Map
Resources

CSS Tutorial

PHP Tutorial

Data Warehousing & Business Intelligence

View this site in:


Traditional Chinese Version SQL 語法教學
German Version SQL-Tutorial
French Version Tutoriel SQL
Spanish Version Tutorial de SQL
Japanese Version SQL 入門
Korean Version SQL 자습서
Simplified Chinese Version SQL 语 句教程

SQL HOME
SQL Intro
SQL Syntax
SQL Select
SQL Distinct
SQL Where
SQL And & Or
SQL Order By
SQL Insert
SQL Update
SQL Delete

SQL Demo
SQL Try It

SQL Advanced
SQL Top
SQL Like
SQL Wildcards
SQL In
SQL Between
SQL Alias
SQL Joins
SQL Inner Join
SQL Left Join
SQL Right Join
SQL Full Join
SQL Union
SQL Select Into
SQL Create DB
SQL Create Table
SQL Constraints
SQL Not Null
SQL Unique
SQL Primary Key
SQL Foreign Key
SQL Check
SQL Default
SQL Create Index
SQL Drop
SQL Alter
SQL Increment
SQL Views
SQL Dates
SQL Nulls
SQL isnull()
SQL Data Types

SQL Functions
SQL Functions
SQL avg()
SQL count()
SQL first()
SQL last()
SQL max()
SQL min()
SQL sum()
SQL Group By
SQL Having
SQL ucase()
SQL lcase()
SQL mid()
SQL len()
SQL round()
SQL now()
SQL format()

SQL Quick Ref


SQL Hosting
SQL Summary

SQL Quiz
SQL Quiz

SQL WHERE Clause


« Previous Next Chapter »

The WHERE clause is used to filter records.


The WHERE Clause

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

WHERE Clause Example

The "Persons" table:


P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 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 Persons
WHERE City='Sandnes'

The result-set will look like this:


P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 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


With the WHERE clause, the following operators can be used:
Operator Description
= Equal
<> Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive rangeOracle Syntax
SQL, Tools, Concepts and Features.
SQL and PL/SQL
SQL*Plus commands (12 pages)
SQL Functions, (Sum, to_date, to_char etc)
Analytic SQL Features (8 pages)
PL/SQL commands (16 pages)
Built-In Packages (84 pages)
Define Variables
NLS Formats
Naming Convention for Oracle
Optimal Flexibile Architecture (OFA)

Tools
IMP, EXP and SQLLDR parameter files
Oracle Networking - TNSNames, Listener.ora
Versions - Features & release dates.
Common Oracle errors

Tables and Columns


Datatypes (Summary for Oracle versions up to 11g)
Data Types and Unicode
Data Integrity - Constraints and Triggers
Tables - Partitioned, Temporary, External and IOT's

Views, Clusters, Indexes


Views and Materialized Views
Clusters and Hash Clusters
Indexes and Sequences

Users and Schemas


Security, Roles and Privileges
Tablespaces
Concurrency - Multi User access

Physical Storage of data


Storage: Blocks, Extents, Segments.
Redo, Rollback, Undo
Archive Log mode

Configuration
Instance startup and shutdown
Oracle Parameters (+ Full List)
Oracle Architecture (Powerpoint)
Parallel processing
Background processes

SQL Scripts
Tablespace Free Space
List all Sessions
List Active Sessions
more scripts can be found on the relevant dictionary pages
Recommended Oracle books

© Copyright SS64.com 1999-2010

You might also like