SQL 6
SQL 6
Chittaranjan Pradhan
Join
Outer Join
Set Operators
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
6.1
Join & Set Operators
Join & Set Operators
Chittaranjan Pradhan
CROSS JOIN
Inner Join
Outer Join
Set Operators
3 Inner Join
4 Outer Join
5 Self Join
6 Set Operators
6.2
Join & Set Operators
Cross Join
Chittaranjan Pradhan
CROSS JOIN
Join
Inner Join
Self Join
Cross join is used to combine information from any two
Set Operators
relations
SELECT Department.deptno, location, ename, eid FROM
Employee, Department;
6.3
Join & Set Operators
Join
Chittaranjan Pradhan
CROSS JOIN
Join
Join
When the required data are present in more than one table, Inner Join
related tables are joined using a join condition. The join Outer Join
condition combines a row in one table with a row in another Self Join
table based on the same values in the common columns Set Operators
Tables are joined on columns that have the same datatype and
data width in the tables. Join operation joins two relations by
merging those tuples from two relations that satisfy a given
condition
6.4
Join & Set Operators
Inner Join
Chittaranjan Pradhan
CROSS JOIN
In the Inner Join, tuples with NULL valued join attributes do not Join
appear in the result. Tuples with NULL values in the join Inner Join
attributes are also eliminated. The different types of inner join Outer Join
Set Operators
Theta Join
Theta join is a join with a specified condition involving a column
from each table. The syntax of theta join is:
SELECT columns FROM tables WHERE join_condition;
When columns are retrieved from more than one table, the use
of a table name qualifier in front of the column name tells the
server to retrieve that column from the specified table
6.5
Join & Set Operators
Inner Join...
Chittaranjan Pradhan
CROSS JOIN
Equi Join
Join
Equi join is a special kind of theta join where the join condition Inner Join
Self Join
6.6
Join & Set Operators
Outer Join
Chittaranjan Pradhan
are: Join
Inner Join
Left Outer Join Outer Join
Left outer join preserves all rows in left table even though there Self Join
is no matching tuples present in the right table. The syntax of Set Operators
CROSS JOIN
Right Outer Join Join
Right outer join preserves all rows in right table even though Inner Join
Outer Join
there is no matching tuples present in left table. The syntax of
Self Join
right outer join is:
Set Operators
SELECT columns FROM table1 RIGHT OUTER JOIN table2
USING(column); or
SELECT columns FROM table1 RIGHT OUTER JOIN table2
ON table1.column= table2.column;
6.8
Join & Set Operators
Outer Join...
Chittaranjan Pradhan
CROSS JOIN
Join
Full Outer Join Inner Join
Full outer join preserves all records in both tables. The syntax Outer Join
SELECT columns FROM table1 FULL OUTER JOIN table2 Set Operators
USING(column); or
6.9
Join & Set Operators
Self Join
Chittaranjan Pradhan
CROSS JOIN
Join
Inner Join
Self Join
Self join is similar to the theta join. It joins a relation to itself by
Set Operators
a condition. When a table is joined to itself, two copies of the
same table are used. The syntax for this is:
SELECT columns FROM table T1, table T2 WHERE
T1.column operator T2.column;
6.10
Join & Set Operators
Set Operators
Chittaranjan Pradhan
CROSS JOIN
Join
Inner Join
Self Join
and INTERSECTION, the relations need to be union
Set Operators
compatible for the result to be a valid relation. The different set
operators are:
UNION
Union is used to combine data from two relations
SELECT name, job FROM Employee WHERE dept=20 UNION
SELECT name, job FROM Employee WHERE dept=30;
6.11
Join & Set Operators
Set Operators...
Chittaranjan Pradhan
CROSS JOIN
Join
DIFFERENCE
Inner Join
Difference is used to identify the rows that are in one relation Outer Join
Set Operators
SELECT name, job FROM Employee WHERE dept=20 MINUS
SELECT name, job FROM Employee WHERE dept=30;
INTERSECTION
Intersection is used to identify the rows that are common to two
relations
SELECT name, job FROM Employee WHERE dept=20
INTERSECT SELECT name, job FROM Employee WHERE
dept=30;
6.12