Explain about joins in sql

SQL Join:-
Sql Join is used to retrieve data from one or more tables joined by common fields. The most common field is Primarykey from one table and foreign key in another table.
EX:-
Select A.Empno, A.Empname, B.Salary, B. Department from Emp1 A, Emp2 B
Where A.Empno=B.Empno
There are two types of joins in SQL
1) Inner joins-Inner join select rows from both tables. Usually join condition is equality of two columns one from table A and other from table B
Syntax
SELECT
FROM
[INNER] JOIN
ON
2) Outer joins
The outer joins have two subtypes
i) Left outer join
II) right outer join
Outer join extends the functionality of inner join. It returns following rows:
The same rows as inner join i.e,. rows from both tables, which matches join condition and
Rows from one or both tables, which do not match join condition along with NULL values in place of other table's columns.
Outer join syntax is as follows: -
SELECT column list
FROM left joined table
LEFT|RIGHT|FULL [OUTER] JOIN
ON join condition
Cross Join:-
Cross join is used to return all records where each row from first table is combined with each row in second table.
Cross join is also called as Cartesian Product join.
Sql Cross Join Syntax:-
Select * FROM TABLE 1 CROSS JOIN TABLE 2
OR
Select * FROM TABLE 1, TABLE 2

No comments:

Post a Comment

Plz Share your comments...