SQL Join
Home
SQL Basics:
SQL HOME
SQL Introduction
SQL Select
SQL Where
SQL And & Or
SQL Between
SQL Distinct
SQL Order By
SQL Try It
SQL Insert
SQL Update
SQL Delete
SQL Count
SQL Advanced:
SQL Functions
SQL Group By
SQL Aliases
SQL Join
SQL Create
SQL Alter
SQL Quiz Test
Resources:
SQL Books
SQL Join
Joins and Keys
Sometimes we have to select data from two tables to make our result complete.
We have to perform a join.
Tables in a database can be related to each other with keys. A primary key is a column
with a unique value for each row. The purpose is to bind data together, across tables, without
repeating all of the data in every
table.
In the "Employees" table below, the "ID" column is the
primary key, meaning that no two rows can have the same ID. The ID
distinguishes two
persons even if they have the same name.
When you look on the example tables below, notice that:
The "ID" column is the primary key of the "Employees"
table
The "ID" column in the "Orders" table is used to refer to the
persons in the "Employees" table without using their names
Employees:
ID
Name
01
Hansen, Ola
02
Svendson, Tove
03
Svendson, Stephen
04
Pettersen, Kari
Orders:
ID
Product
01
Printer
03
Table
03
Chair
Example
Who has ordered a product, and what did they order?
SELECT Employees.Name, Orders.Product
FROM Employees, Orders
WHERE Employees.ID = Orders.ID
Result
Name
Product
Hansen, Ola
Printer
Svendson, Stephen
Table
Svendson, Stephen
Chair
Example
Who ordered a printer?
SELECT Employees.Name
FROM Employees, Orders
WHERE Employees.ID = Orders.ID
AND Orders.Product = 'Printer'
Result
Name
Hansen, Ola
Jump to : Top Of Page or HOME.
We Help you for free. Please Help us!
Help us correct errors
Help us with spelling and grammar
Tell us what you think
Link to us from your pages
All information in this Web is for training only. We do not make any warranties of its correctness or
its fitness to be used. The risk of using it remains with the user.
Copyright © 1999-2001 by Refsnes Data. All Rights Reserved.
More Tutorials:
HTML XHTML
XML XSL
CSS DTD
WAP WML
JavaScript
DHTML Flash
VBScript ASP
SQL AppML
News:
The Future ofProgramming
Web Security
Browser News
Web Standards
References:
HTML 4.01 Ref
XHTML 1.0 Ref
WML 1.1 Ref
CSS Reference
XSLT Elements
ASCII Reference
Entity Reference
HTML Colors
Color Values
Color Names
WAP Pages
Validation:
HTML XHTML
CSS DTD
XML WML
About W3Scripts
Please link to us
Larger Text?
XML Partners:
Wyszukiwarka
Podobne podstrony:
sql functions aspsql groupby aspsql alter aspsql orderby aspsql alias aspsql create aspsql where aspsql quiz aspsql count aspsql select aspsql distinct aspsql insert aspsql update aspsql intro aspsql tryit aspsql?lete aspJoin (SQL) – Wikipedia, wolna encyklopediasql and or aspwięcej podobnych podstron