You are on page 1of 2

3) what is joins in sql and types of joins in sql?

a) Joins are used to retrive the data two or more relatedtables or SQL JOIN clause is used to
combine rows from

two or more tables, based on a common field between them.

join types: 1)inner join

2)outerjoin

3)self join

4) cross join

1)inner join: inner join returns only matcheching rows in both tables. Non matching rows are
eliminated.

syntax: select var1,var2 from table1 join table2 on table1.matchedvar= table2.matchedvar.

2)outerjoin: Outer join returns all the rows of both tables whether it has matched or not. it is
devided into three types.

a) Left outer join

b) Right outer join

c) Full outer join

a) Left outer join: Left outer join display the all rows in left table and matched rows in right table.

syntax: select var1,var2 from table1 left join table2 on table1.matchedvar=


table2.matchedvar.

b) Right outer join: Right outer join display the all rows in right table and matched rows in left
table.
syntax: select var1,var2 from table1 right join table2 on table1.matchedvar=
table2.matchedvar.

c) Full outer join:Full outer join returns all the rows from both tables whether it has been
matched or not.

syntax: select var1,var2 from table1 full outer join table2 on table1.matchedvar=
table2.matchedvar.

3)self join: join of a table to itself is called self join. In this join table appers twicein the form
clause and is followed by table

that qualify column names in the join condition.

4) cross join:A cross join that produces Cartesian product of the tables that are involved in the
join. The size of a Cartesian product is the number of the rows in the first table

multiplied by the number of rows in the second table

syntax:

SELECT * FROM Employee cross join Departments e2

SELECT * FROM Employee , Departments e2

You might also like