MAKE FULL WEB APPLICATION WITH JUST SQL KNOWLEDGE? CLICK HERE
A join is used to combine rows from multiple tables. A join is
performed whenever two or more tables is listed in the FROM clause
of an SQL statement. There are different kinds of joins.
The SQL JOIN clause is used whenever we have to select data
from 2 or more tables.
To be able to use SQL JOIN clause to extract data from 2
(or more) tables, we need a relationship between certain columns
in these tables.
The Syntax of join clause :-
SELECT Column_name,column_name[,column_name]
FROM table_name JOIN table_name
ON table_name.ref_column_namejoin_operator table_name.
ref_column_name
|
EXAMPLE # 1:-
Customer Table :-
CUSTOMER ID
|
FIRST NAME
|
LAST NAME
|
1
|
Deepali
|
Thakkar
|
2
|
Pavan
|
Shah
|
3
|
Aryan
|
Vora
|
4
|
Yashika
|
Mehta
|
Sales Table :-
CUSTOMER ID
|
DATE
|
SALES AMOUNT
|
2
|
5/6/2006
|
100.22
|
1
|
5/7/2006
|
99.95
|
3
|
5/7/2006
|
122.95
|
3
|
5/9/2006
|
100.00
|
4
|
5/12/2006
|
555.55
|
As you can see those 2 tables have common field called CustomerID
and we can extract information from both tables by matching
their CustomerID columns.
Consider the following SQL statement :-
SELECT Customers. First Name, Customers.Last Name, SUM(Sales.SaleAmount)
AS Sales Per Customer FROM Customers, Sales WHERE Customers.Customer
ID = Sales.
Customer ID GROUP BY Customers.
First Name, Customers.Last Name
|
RESULT:-
FIRST NAME
|
LAST NAME
|
SALES PER CUSTOMER
|
Deepali
|
Thakkar
|
99.95
|
Pavan
|
Shah
|
100.22
|
Aryan
|
Vora
|
222.95
|
Yashika
|
Mehta
|
555.55
|
If you don't find what you are looking for. Please click
here to submit your query, our experts will reply soon.
|