What is Join in SQL Server and how many types of Joins in SQLServer?

Asked 14-Sep-2021
Viewed 289 times

0

What is Join in SQL Server and how many types of Joins in SQLServer? Why are use the Join in Database?


1 Answer


0

SQL JOIN Command :
 The SQL JOIN query is used to combine two or more tables based on common column name to retrieve record from all that tables.
Types of SQL JOIN Command :
 There are 4 types of JOIN Command are used in SQL Server.
1- Inner join.
2- Left join.
3- Right join.
4- Full outer join.
Inner join
 In SQL Inner join there are common record from all table is retrieved based on condition
                                What is Join in SQL Server and how many types of Joins in SQLServer?
Left join :
In SQL in Left join all the record from Left table is selected and the common record from Right table are selected base on condition.
                            What is Join in SQL Server and how many types of Joins in SQLServer?
Right join :
 In SQL Server in Right join all the record from right table and common record of left table is execute.
                              What is Join in SQL Server and how many types of Joins in SQLServer?
Full outer join :
 Full outer join retrieve all record from each tables which are connected with SQL statement.
                                What is Join in SQL Server and how many types of Joins in SQLServer?
Example : 
There are two tables ‘Customer’ and ‘Salesman’ are as-
 Customer :            What is Join in SQL Server and how many types of Joins in SQLServer?

Salesman :            What is Join in SQL Server and how many types of Joins in SQLServer?

Inner Join :
Following the statement select the common record from both table base on common column name i.e. ‘salesman_id’ is in both tables.
                select * from Customer inner join Salesman on Customer.salesman_id=Salesman.salesman_id;
        What is Join in SQL Server and how many types of Joins in SQLServer?

Left join :
Following the statement select all data from Left table ‘Customer’ and common data from Right table 

                    select * from Customer left join Salesman on
                    Customer.salesman_id=Salesman.salesman_id;
            What is Join in SQL Server and how many types of Joins in SQLServer?

Right join
The following statement select all record form Right table ‘Salesman’ and the common record from Left table ‘Customer’.
                    select * from Customer right join Salesman on
                    Customer.salesman_id=Salesman.salesman_id;
            What is Join in SQL Server and how many types of Joins in SQLServer?

Full outer join :
 The following SQL statement select all the record from Left table ‘Customer’ and Right table ’Salesman’.
                        select * from Customer full outer join Salesman on
                        Customer.salesman_id=Salesman.salesman_id;

            What is Join in SQL Server and how many types of Joins in SQLServer?