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.
They are two types of Joins are available in SQL SERVER
1). Inner Join (Equal Join) 2). Outer Join
1). Inner Join (Equal Join)
The INNER JOIN will select all rows from both tables as long as there is a match between the columns we are matching on.
EX:- Select a.Emp_no, Emp_name, Department from emp_master a, Dept_master b where a.dept_id = b.dept_id
or
Select a.Emp_no, Emp_name, Department from emp_master a inner join Dept_master b on a.dept_id = b.dept_id
2) Outer Joins They are two types of Outer joins are their. a)Left outer join b)right outer join
a). Left Outer Joins :
The LEFT OUTER JOIN or simply LEFT JOIN (you can omit the OUTER keyword in most databases), selects all the rows from the first table listed after the FROM clause, no matter if they have matches in the second table
Outer join syntax is as follows: -
SELECT a.* FROM emp_master a left outer join dept_master b ON a.dept_id = b.dept_id
b). Right Outer Joins :
The RIGHT OUTER JOIN or just RIGHT JOIN behaves exactly as SQL LEFT JOIN, except that it returns all rows from the second table (the right table in our SQL JOIN statement).
Outer join syntax is as follows: -
SELECT a.* FROM emp_master a Right outer join dept_master b ON a.dept_id = b.dept_id
|
No responses found. Be the first to respond and make money from revenue sharing program.
|