07 Join Queries
07 Join Queries
Week 8
Muhammad Qasim
Different Types of SQL JOINs
Here are the different types of the JOINs in SQL:
(INNER) JOIN: Returns records that have matching values in both
tables
LEFT (OUTER) JOIN: Returns all records from the left table, and
the matched records from the right table
RIGHT (OUTER) JOIN: Returns all records from the right table,
and the matched records from the left table
FULL (OUTER) JOIN: Returns all records when there is a match in
either left or right table
Different Types of SQL JOINs
Inner Join
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
SELECT *
FROM Customer inner join Employee
ON Customer.CustomerID=Employee.EmployeeID;
Left Join
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
SELECT *
FROM Customer
ON Customer.CustomerID=Employee.EmployeeID;
Right Join
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
SELECT *
FROM Customer
ON Customer.CustomerID=Employee.EmployeeID;
Full Join or Full outer Join
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
Question: Write a query to pull a list with salesman name, customer name and their
cities for the salesmen and customer who belongs to the same city.