
The SQL table combine the two or more rows using the join clause. In the SQL query have many types of join clause like inner join, Left Join, right join, Full Join, Cross Join, Self-Join. Now we discuss every type of join clause and write the example code given bellow:
Inner join: This join work when match the data from both tables
SELECT * FROM Employee INNER JOIN Salary ON Employee.Id = Salary.Id;
Left Join: This Join work the left table match the right table and also if they don’t match the row then the right table column value is return null.
SELECT * FROM Employee LEFT JOIN Salary ON Employee.Id = Salary.Id;
Right Join: This Join work the right table match the left table and also if they don’t match the row then the left table column value is return null.
SELECT * FROM Employee right JOIN Salary ON Employee.Id = Salary.Id;
Full Join: This Join work the right table match the left table and also match the left table match the right table. If they don’t match the row from any table of identity column then the tables column value is return null.
select Employee.Name,Employee.Phone,Salary.Gendar,Salary.Salary from Employee full join Salary on Salary.Id=Employee.Id
Cross Join: This Join work the first table row match the second column all rows, It’s also called as cartesian product. In this all the records of the first table comes with all the records of second table. In this condition is not used.
select * from Employee,Salary
Self-Join: This Join work the table itself. When we have one table but the table have one primary key and one foreign key on the other hand, we need the data base on foreign key then we join the table itself then it’s called the self-join.
SELECT a.FirstName,b.Salary FROM Salary a, Salary b WHERE a.Salary < b.Salary;