SQL
SQL
One of the most important features of SQL is the ability to define relationships between multiple
tables and draw information from them in terms of these relationships, all within a single command.
Join Condition
Condition specified in the where clause to evaluate the joins is called Join Condition. Most of the
queries contain Join Conditions that compare two or more columns.
Example: -
For joins having three tables, Oracle joins first two of them based on the join condition and then
joins with the third one based on the join condition containing third table. Oracle does this process
until all tables are joined.
Types of Joins:
1) Equi Join
2) Non-Equi Joins
3) Self-Join
4) Cross join (Cartesian Join)
5) Outer join
a) Left outer join
b) Right outer join
c) Full outer join
1) Equi join -
When two tables joined together using equality operator, then it is called Equi Join. This join
retrieves information by using equality condition. This is represented by (=) sign.
Example:
List the employee numbers, names, department numbers and dept names
Here, the deptno column exists in both the tables. To avoid ambiguity, the column name
should be qualified with the table name. Both the table names need to be specified (emp and
dept) where clause defines the joining condition.
2) Non Equi Join -
A nonequi join is an inner join statement that uses an unequal operation (i.e.: <>, >, <, !=,
BETWEEN, etc.) to match rows from different tables.
Example:
Write a query to display those employees details whose salary of emp1 table >= salary of
emp table employees
3) Self-Join –
To join a table to itself means that each row of the table is combined with itself with every
other row of the table. The self-join can be viewed as a join of two copies of the same table.
The table is not actually copied, but SQL performs the command as though it were.
Example:
List out the names of the manager with the employees in the emp table
5) Outer Join –
Outer Join is used to join tables with sparse data in one or more table for the columns used
in the join condition. Outer join returns all rows which satisfies the join condition plus other
records from one table and no records from other table. The column will be nullified for the
records has no data.