Vous êtes sur la page 1sur 4

EXPERIMENT-8

AIM – To Study Various Types Of Joins.

JOINS 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.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. Tables in a database are often
related to each other with keys. For example, a primary key is used to bind data together,
across tables, without repeating all of the data in every table. A SQL Join condition is
used in the SQL WHERE Clause of select, update, delete statements. The Syntax for
joining two tables is

There are different kinds of joins

1. EQUI JOINS It is a simple sql join condition which uses the equal sign as the
comparison operator. It is a specific type of comparator-based join that uses only equality
comparisons in the join-predicate. Using other comparison operators (such as <)
disqualifies a join as an EQUI-JOIN. The syntax for the EQUI-JOIN is

SELECT col1, col2, col3...


FROM table_name1, table_name2
WHERE table_name1.col2 = table_name2.col1;

For example, the output for the EQUI-JOIN is shown in the tables related to project

The above command displays the students whose result is declared.


2. OUTER JOINS  An outer join does not require each record in the two joined
tables to have a matching record. The joined table retains each record—even if no other
matching record exists. Outer joins subdivide further into left outer joins, right outer
joins, and full outer joins, depending on which table(s) one retains the rows from (left,
right, or both). The syntax for the OUTER-JOIN is

SELECT col1, col2, col3...


FROM table_name1, table_name2
WHERE table_name1.col2 = table_name2.col1(+);

OR

SELECT col1, col2, col3...


FROM table_name1, table_name2
WHERE table_name1.col2(+) = table_name2.col1;

For example, the output for the OUTER-JOIN is shown in the tables related to project
The above command displays the students whose result is declared as well as not.

CARTESIAN JOIN The Cartesian product, also referred to as a cross-join, returns all
the rows in all the tables listed in the query. Each row in the first table is paired with all
the rows in the second table. This happens when there is no relationship defined between
the two tables. A cross join returns the cartesian product of the sets of records from the
two joined tables. Thus, it equates to an inner join where the join-condition always
evaluates to True or where the join-condition is absent from the statement. In other
words, a cross join combines every row in B with every row in A. The number of rows in
the result set will be the number of rows in A times the number of rows in B.
Thus, if A and B are two sets, then the cross join is written as A × B. The syntax for the
CARTESIAN-JOIN is

SELECT *
From <TABLE1> <TABLE2> ;

For example, the output for the CARTESIAN-JOIN is shown in the tables related to
project
SELF JOINS A self-join is a query in which a table is joined (compared) to itself.
Self-joins are used to compare values in a column with other values in the same column
in the same table. One practical use for self-joins: obtaining running counts and running
totals in an SQL query. To write the query, select from the same table listed twice with
different aliases, set up the comparison, and eliminate cases where a particular value
would be equal to itself. To list a table two times in the same query, you must provide a
table alias for at least one of instance of the table name. This table alias helps the query
processor determine whether columns should present data from the right or left version of
the table. ). The syntax for the SELF-JOIN is

SELECT col1, col2, col3...


FROM table_A A
INNER JOIN table_A B ON A.col1 = B.col2….
WHERE row conditions

For example, the output for the SELF-JOIN is shown in the tables related to project

Vous aimerez peut-être aussi