Prerequisite – Introduction of MS SQL Server
1. Left Join :
A join combines the set of two tables only. A left join is used when a user wants to extract the left table’s data only. Left join not only combines the left table’s rows but also the rows that match alongside the right table.
select select_list from table1 left join table2 on join_predicate (OR) select * from table1 right join table2
2. Right Join :
Right join combines the data of the right table and the rows that match both the tables.
select select_list from table1 right join table2 on join_predicate (OR) select * from table1 right join table2
The first table is the Course table which is considered the left table and the second table is the Student table which is considered the right table.
1. Left Join :
Left join is applied to the tables Course and Student and the table below is the result set.
select name, course from c.course left join s.student on c.age = s.age
The left table and its corresponding matching rows on the right table are displayed. If a user wants to display the rows only in the left table, where clause can be used in the query. Left join is usually used for a maximum of two tables but in case of SQL Server, it can be used for multiple tables too.
2. Right Join :
Right join is applied to the tables Course and Student and the table below is the result set.
select name, rollno from c.course right join s.student on c.age = s.age
If the tables do not have common rows, it displays the rows as NULL. The right join can also be used for multiple tables.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- SQL | Join (Cartesian Join & Self Join)
- Full join and Inner join in MS SQL Server
- Self Join and Cross Join in MS SQL Server
- SQL | Join (Inner, Left, Right and Full Joins)
- Difference between Inner Join and Outer Join in SQL
- Difference between Natural join and Inner Join in SQL
- Difference between Natural join and Cross join in SQL
- SQL | EQUI Join and NON EQUI JOIN
- Difference between Left, Right and Full Outer Join
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- Difference between Nested Loop Join and Hash Join
- Difference between Nested Loop join and Sort Merge Join
- Difference between Hash Join and Sort Merge Join
- Inner Join vs Outer Join
- Difference between JOIN and UNION in SQL
- SQL Join vs Subquery
- SQL | UPDATE with JOIN
- Mean and Mode in SQL Server
- Copy tables between databases in SQL Server using Import-and-Export Wizard
- Difference between MySQL and MS SQL Server
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.