Database Management System Practical No: 7 Aim: 1. To Perform Join Operations
Database Management System Practical No: 7 Aim: 1. To Perform Join Operations
Practical No : 7
SQL JOIN
An SQL JOIN clause is used to combine rows from two or more tables, based on a common field
between them.
The INNER JOIN keyword selects all rows from both tables as long as there is a match between
the columns in both tables.
Syntax
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
Syntax
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON
table1.column_name=table2.column_name;
Syntax
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON
table1.column_name=table2.column_name;
The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.
Syntax
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON
table1.column_name=table2.column_name;
SELECT a.column_name, b.column_name...
FROM table1 a, table1 b
WHERE a.common_filed = b.common_field;
SQL UNION :
The SQL UNION operator combines the result of two or more SELECT statements.
Syntax:
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
SQL INTERSECT:
The SQL Intersect operator returns all the results which are common in two or more SELECT
statements.
Syntax:
SELECT column_name(s) FROM table1
Intersect
SELECT column_name(s) FROM table2;
SQL EXCEPT:
The SQL Except operator returns all the results which are in the result of first but not in the
result of second SELECT statement (Set-Difference).
Syntax:
SELECT column_name(s) FROM table1
Except
SELECT column_name(s) FROM table2;