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

SQL Commands

Ratings: (0)|Views: 4,844 |Likes:
Published by simply_coool
SQL Commands
SQL Commands

More info:

Published by: simply_coool on Aug 12, 2009
Copyright:Attribution Non-commercial


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





Basics of the SELECT Statement
In a relational database, data is stored in tables. An example table would relate Social Security Number, Name, andAddress:
512687458JoeSmith83 First StreetHowardOhio758420012MaryScott842 Vine Ave.LosantivilleOhio102254896SamJones33 Elm St.ParisNew Yor876512563SarahAckerman440 U.S. 110UptonMichigan
Query 1
let’s say you want to see the address of each employee. Use the SELECT statement, like so:
Conditional Selection
To further discuss the SELECT statement, let's look at a new example table (for hypothetical purposes only):
Relational Operators
There are six Relational Operators in SQL, and after introducing them, we'll see how they're used:=Equal< or != (seemanual) Not Equal<Less Than>Greater Than<=Less Than or Equal To>=Greater Than or Equal ToThe
clause is used to specify that only certain rows of the table are displayed, based on the criteria describedin that
WHERE clause
. It is most easily understood by looking at a couple of examples.
Query 2
EMPLOYEEIDNO's of those making at or over $50,000
operator joins two or more conditions, and displays a row only if that row's data satisfies
conditionslisted (i.e. all conditions hold true).
Query 3
To display all staff making over $40,000, use:The
operator joins two or more conditions, but returns a row if 
of the conditions listed hold true.
Query 4
To see all those who make less than $40,000 or have less than $10,000 in benefits, listed together, use the followingquery:AND & OR can be combined, for example:
Query 5
Find all managers whose salary is greater than 60000 and benefits are greater than 12000
An easier method of using compound conditions uses
Query 6
For example, if you wanted to list all managers and staff:
Query 7
To list those making greater than or equal to $30,000, but less than or equal to $50,000, use:
Query 8
To list everyone not in this range, try:
Query 9
Look at the EmployeeStatisticsTable, and say you wanted to see all people whose last names started with "S"; try:
In this section, we will only discuss
joins, and
, as in general, they are the most useful. For moreinformation, try the SQL links at the bottom of the page.Good database design suggests that each table lists data only about a single
, and detailed information can beobtained in a relational database, by using additional tables, and by using a
0150Bed0215Table1502Chai2150Mirro5001Des0121Cabinet0221Coffee Table1550Chai0115Jewelry Box0221Pottery2102Bookcase5001Plant Stand
First, let's discuss the concept of 
. A
 primary key
is a column or set of columns that uniquely identifies the rest of the data in any given row. For example, in the AntiqueOwners table, the OwnerID column uniquely identifies that row.This means two things: no two rows can have the same OwnerID, and, even if two owners have the same first and lastnames, the OwnerID column ensures that the two owners will not be confused with each other, because the uniqueOwnerID column will be used throughout the database to track the owners, rather than the names.A
foreign key
is a column in a table where that column is a primary key of another table, which means that any data in aforeign key column must have corresponding data in the other table where that column is the primary key. In DBMS-speak, this correspondence is known as
referential integrity
. For example, in the Antiques table, both the BuyerID andSellerID are foreign keys to the primary key of the AntiqueOwners table (OwnerID; for purposes of argument, one hasto be an Antique Owner before one can buy or sell any items), as, in both tables, the ID rows are used to identify theowners or buyers and sellers, and that the OwnerID is the primary key of the AntiqueOwners table. In other words, all

Activity (28)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
sangho,woo liked this
vijay306 liked this
syriluit liked this
Ashi Sharma liked this
Mohammad Alam liked this

You're Reading a Free Preview

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