0% found this document useful (0 votes)
37 views3 pages

Joins

This document discusses different types of joins in SQL including inner joins, outer joins, self joins and cross joins. Tables t1 and s2 are created and sample data is inserted. Equi, non-equi and self joins are demonstrated between t1 and s2. Additional tables s5 are created and sample data inserted to demonstrate inner, inner using, natural and cross joins. Left, right and full outer joins are also shown between tables t1 and s5.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views3 pages

Joins

This document discusses different types of joins in SQL including inner joins, outer joins, self joins and cross joins. Tables t1 and s2 are created and sample data is inserted. Equi, non-equi and self joins are demonstrated between t1 and s2. Additional tables s5 are created and sample data inserted to demonstrate inner, inner using, natural and cross joins. Left, right and full outer joins are also shown between tables t1 and s5.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

PANIMALAR ENGINEERING COLLEGE

DEPARTMENT OF CSE

EX NO 5: CREATING RELATIONSHIP BETWEEN DATABASES USING


JOINS
CREATING AND INSERTING VALUES IN TABLE
SQL> create table t1(sno1 number(30), name varchar(30));
Table created.
SQL> create table s2(sno3 number(30), total number(30));
Table created.
SQL> insert into t1 values (1,'a');
1 row created.
SQL> insert into t1 values (2,'b');
1 row created.
SQL> insert into t1 values (3,'c');
1 row created.
SQL> insert into s2 values (1,300);
1 row created.
SQL> insert into s2 values (5,1300);
1 row created.
SQL> insert into s2 values (51,12300);
1 row created.
SIMPLE JOIN
EQUI JOIN
SQL> select * from t1,s2 where t1.sno1=s2.sno3;
SNO1 NAME
SNO3 TOTAL
---------- ------------------------------ ---------- ---------1a
1
300
NON EQUI JOIN
SQL> select * from t1,s2 where t1.sno1<s2.sno3;
SNO1 NAME
SNO3 TOTAL
---------- ------------------------------ ---------- ---------1a
5
1300
1a
51
12300
2b
5
1300
2b
51
12300
3c
5
1300
3c
51
12300
6 rows selected.
SELF JOIN
SQL> select * from t1,s2 where t1.sno1=s2.sno3;
SNO1 NAME
SNO3 TOTAL
---------- ------------------------------ ---------- ---------1a
1
300

PANIMALAR ENGINEERING COLLEGE


DEPARTMENT OF CSE

SQL> create table s5 (sno1 number(30) ,total number (30));


Table created.
SQL> insert into s5 values (1,300);
1 row created.
SQL> insert into s5 values (2,1300);
1 row created.
SQL> insert into s5 values (3,11300);
1 row created.
INNER JOIN
SQL> select * from t1 inner join s5 using (sno1);
SNO1 NAME
TOTAL
---------- ------------------------------ ---------1a
300
2b
1300
3c
11300
INNER JOIN USING JOIN
SQL> select * from t1 join s5 using (sno1);
SNO1 NAME
TOTAL
---------- ------------------------------ ---------1a
300
2b
1300
3c
11300
NATURAL JOIN
SQL> select * from t1 natural join s5 ;
SNO1 NAME
TOTAL
---------- ------------------------------ ---------1a
300
2b
1300
3c
11300
CROSS JOIN
SQL> select * from t1 cross join s5 ;
SNO1 NAME
SNO1 TOTAL
---------- ------------------------------ ---------- ---------1a
1
300
1a
2
1300
1a
3
11300
2b
1
300
2b
2
1300
2b
3
11300
3c
1
300
3c
2
1300
3c
3
11300
9 rows selected.

PANIMALAR ENGINEERING COLLEGE


DEPARTMENT OF CSE

SQL> insert into s5 values (8,300);


1 row created.
SQL> insert into t1 values (10,300);
1 row created.
LEFT OUTER JOIN
SQL> select * from t1 left outer join s5 on t1.sno1=s5.sno1;
SNO1 NAME
SNO1 TOTAL
---------- ------------------------------ ---------- ---------1a
1
300
2b
2
1300
3c
3
11300
10 300
RIGHT OUTER JOIN
SQL> select * from t1 right outer join s5 on t1.sno1=s5.sno1;
SNO1 NAME
SNO1 TOTAL
---------- ------------------------------ ---------- ---------1a
1
300
2b
2
1300
3c
3
11300
8
300
FULL OUTER JOIN
SQL> select * from t1 full outer join s5 on t1.sno1=s5.sno1;
SNO1 NAME
SNO1 TOTAL
---------- ------------------------------ ---------- ---------1a
1
300
2b
2
1300
3c
3
11300
8
300
10 300

You might also like