Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
36Activity
0 of .
Results for:
No results containing your search query
P. 1
SQL Commands

SQL Commands

Ratings:

4.5

(2)
|Views: 1,002|Likes:
Published by api-3718877

More info:

Published by: api-3718877 on Oct 14, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

SQL COMMANDS

SQL SELECT
SQL DISTINCT
SQL WHERE
SQL AND OR
SQL IN
SQL BETWEEN
SQL LIKE
SQL ORDER BY
SQL Aggregate Functions
SQL COUNT
SQL GROUP BY
SQL HAVING

SQL ALIAS

SQL JOIN
SQL OUTER JOIN
SQL CONCATENATE
SQL SUBSTRING
SQL TRIM

SELECT

What do we use SQL commands for? A common use is to select data from the tables
located in a database. Immediately, we see two keywords: we need toSELECT
informationFROM a table. (Note that a table is a container that resides in the
database where the data is stored. For more information about how to manipulate
tables, go to the Table Manipulation Section). Hence we have the most basic SQL
structure:

SELECT "column_name" FROM "table_name"
To illustrate the above example, assume that we have the following table:
TableStore_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 shall use this table as an example throughout the tutorial (this table will appear
in all sections). To select all the stores in this table, we key in,
SELECTstore_na me FROMStore_Informat ion
Result:
store_name
Los Angeles
San Diego
Los Angeles
Boston
Multiple column names can be selected, as well as multiple table names.
DISTINCT
TableStore_Information
store_name Sales Date
Los Angeles $1500Jan-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

store_name
Sales Date
Los Angeles $1500Jan-05-1999
San Diego
$250 Jan-07-1999
Los Angeles
$300 Jan-08-1999
Boston
$700 Jan-08-1999
we key in,

SELECT store_name
FROM Store_Information
WHERE Sales > 1000

Result:
store_name
Los Angeles
AND OR

In the previous section, we have seen that theWHER E keyword can be used to
conditionally select data from a table. This condition can be a simple condition (like
the one presented in the previous section), or it can be a compound condition.
Compound conditions are made up of multiple simple conditions connected byAND
orOR. There is no limit to the number of simple conditions that can be present in a
single SQL statement.

The syntax for a compound condition is as follows:

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

The {}+ means that the expression inside the bracket will occur one or more times.
Note thatAND andOR can be used interchangeably. In addition, we may use the
parenthesis sign () to indicate the order of the condition.

For example, we may wish to select all stores with sales greater than $1,000 or all
stores with sales less than $500 but greater than $275 in TableStore_Infor mation,
TableStore_Information
store_name
Sales Date
Los Angeles
$1500
Jan-05-1999
San Diego
$250 Jan-07-1999
San Francisco
$300 Jan-08-1999
Boston
$700 Jan-08-1999
we key in,
SELECT store_name
FROM Store_Information

Activity (36)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Anware Kade liked this
scribd8421 liked this
scribd8421 liked this
Nabil BrezZy liked this
Rishap Sharma liked this
Rishap Sharma liked this
mp.joshi8370 liked this
mano555 liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->