SQL
joins has five type of keywords.
namely,
INNER
JOIN
OUTER
JOIN
LEFT
JOIN
RIGHT
JOIN
FULL
JOIN
INNER JOIN:
The INNER JOIN keyword return rows when there is at least one
match in both tables.
Syntax:
SELECT column_name(s) FROM
tablename1 as t1 INNER JOIN tablename2 as t2 ON t1.column_name=t2.column_name
SQL INNER JOIN Example
The table “Customer” is,
Id
|
Name
|
Address
|
City
|
1
|
Vaishnavi
|
10,Anna Nagar
|
Bangalore
|
2
|
Shajil
|
23,T.Nagar
|
Chennai
|
3
|
Vinoth
|
20,Sivaji Street
|
Chennai
|
The table “Order” is,
O_Id
|
OrderNo
|
Id
|
1
|
77895
|
3
|
2
|
44678
|
3
|
3
|
22456
|
1
|
4
|
24562
|
1
|
5
|
34764
|
15
|
Query:
SELECT C.Name, C.City,
O.OrderNo FROM Customer as C INNER JOIN Orders as O ON C.Id=O.Id
The result-set will be:
Name
|
City
|
OrderNo
|
Vaishnavi
|
Bangalore
|
22456
|
Vaishnavi
|
Bangalore
|
24562
|
Vinoth
|
Chennai
|
77895
|
Vinoth
|
Chennai
|
44678
|
Note that, the INNER JOIN keyword return rows when there is at
least one match in both tables. If there are rows in "Customer" that
do not have matches in "Orders", those rows will NOT be listed.
No comments:
Post a Comment