• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Joins
 

Joins

on

  • 161 views

It clarifies the doubts like types of joins,why we use joins and where we use self join

It clarifies the doubts like types of joins,why we use joins and where we use self join

Statistics

Views

Total Views
161
Views on SlideShare
161
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Joins Joins Document Transcript

    • Why we use joins??? Types of joins: Inner join Outer Join (left join,right join,full outer join) Self join The below image gives the summary of all joins
    • Inner join: We use inner joins to get all the information from two tables which satisfies the condition. Inner joins give only matching records from the tables. The problem with inner join is that it will display only matching records. We can even join more than two tables. Outer Join: Outer join displays all the rows of left table(table1) and all the rows of right
    • table(table 2) It is the combination of left and right join. Left Join: But if we want to get all the records from table 1 and the matching records of table1 and table2,we use left join in that case. Left join displays all the records of table 1 and matching records of table 1 and table 2.In case, if there are no values for the particular column,they will be replaced by NULL So, we use a left join which keeps all the data on the "left" (table 1) and pulls in any matching data on the "right" (table 2)
    • We can even join more than two tables. Right Join: But if we want to get all the records from table 2 and the matching records of table1 and table2,we use right join in that case. Right join displays all the records of table 2 and matching records of table 1 and table 2.In case, if there are no values for the particular column,they will be replaced by NULL So, we use a right join which keeps all the data on the "right" (table 2) and pulls in any matching data on the "left" (table 1) We can even join more than two tables.
    • There is also another kind of join called as self join. You use a self join when a table references data in itself. E.g., an Employee table may have a SupervisorID column that points to the employee that is the boss of the current employee. To query the data and get information for both people in one row, you could self join like this: select e1.EmployeeID, e1.FirstName, e1.LastName, e1.SupervisorID, e2.FirstName as SupervisorFirstName, e2.LastName as SupervisorLastName from Employee e1 left outer join Employee e2 on e1.SupervisorID = e2.EmployeeID
    • There is also another kind of join called as self join. You use a self join when a table references data in itself. E.g., an Employee table may have a SupervisorID column that points to the employee that is the boss of the current employee. To query the data and get information for both people in one row, you could self join like this: select e1.EmployeeID, e1.FirstName, e1.LastName, e1.SupervisorID, e2.FirstName as SupervisorFirstName, e2.LastName as SupervisorLastName from Employee e1 left outer join Employee e2 on e1.SupervisorID = e2.EmployeeID