0% found this document useful (0 votes)
9 views4 pages

Joins 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Joins 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Joins:

-----
Using joins we can retrives the data from more than one table.

Types:
-----
1. Equi join -->It retrives the matching records from the tables.
2. Inner join -->It retrives the matching records from the tables.
3. Outer joins
(i) Left outer join -->all the records from the left table and corresponding
matching records from the right table.
(ii) Right outer join -->all the records from the right table and corresponding
matching records from the left table.
(iii) Full outer join -->retrives matching records from the both tables and non
matching records from the left and right tables.
4. Cross join
5. Self join
6. Natural join

SQL> CREATE TABLE T1


2 (A NUMBER);

Table created.

SQL> INSERT INTO T1 VALUES(1);

1 row created.

SQL> INSERT INTO T1 VALUES(2);

1 row created.

SQL> INSERT INTO T1 VALUES(3);

1 row created.

SQL> INSERT INTO T1 VALUES(4);

1 row created.

SQL> INSERT INTO T1 VALUES(5);

1 row created.

SQL> INSERT INTO T1 VALUES(1);

1 row created.

SQL> CREATE TABLE T2


2 (A NUMBER);

Table created.

SQL> INSERT INTO T2 VALUES(1);

1 row created.

SQL> INSERT INTO T2 VALUES(2);


1 row created.

SQL> INSERT INTO T2 VALUES(3);

1 row created.

SQL> INSERT INTO T2 VALUES(3);

1 row created.

SQL> INSERT INTO T2 VALUES(6);

1 row created.

SQL> INSERT INTO T2 VALUES(7);

1 row created.

SQL> SELECT * FROM T1;

A
----------
1
2
3
4
5
1

6 rows selected.

SQL> SELECT * FROM T2;

A
----------
1
2
3
3
6
7

6 rows selected.

SQL> SELECT T1.*, T2.* FROM T1, T2 WHERE T1.A=T2.A;

A A
---------- ----------
1 1
1 1
2 2
3 3
3 3

SQL> SELECT T1.*, T2.* FROM T1 INNER JOIN T2 ON T1.A=T2.A;

A A
---------- ----------
1 1
1 1
2 2
3 3
3 3

SQL> SELECT T1.*, T2.* FROM T1 LEFT OUTER JOIN T2 ON T1.A=T2.A;

A A
---------- ----------
1 1
1 1
2 2
3 3
3 3
5
4

7 rows selected.

SQL> SELECT T1.*, T2.* FROM T1 RIGHT OUTER JOIN T2 ON T1.A=T2.A;

A A
---------- ----------
1 1
2 2
3 3
3 3
1 1
6
7

7 rows selected.

SQL> SELECT T1.*, T2.* FROM T1 FULL OUTER JOIN T2 ON T1.A=T2.A;

A A
---------- ----------
1 1
1 1
2 2
3 3
3 3
6
7
5
4

9 rows selected.

T3(A)
-----
1
1
1
0
0
7
T4(A)
----
1
1
0
0
5
6

You might also like