350 likes | 570 Views
This article provides a detailed explanation of the different types of joins, including inner join, left join, right join, and full join. Learn how to connect two or more tables using SQL join commands and discover the various scenarios where each type of join is applicable.
E N D
Types of Joins • Farrokh Alemi, Ph.D.
Inner Join SELECTcolumn_name(s)FROM table1 INNERJOIN table2 ON table1.column_name = table2.column_name;
Inner Join Unique or Addressed SELECTcolumn_name(s)FROM table1 INNERJOIN table2 ON table1.column_name = table2.column_name;
Inner Join SELECTcolumn_name(s)FROM table1 INNERJOIN table2 ON table1.column_name = table2.column_name;
Inner Join • Inner Join SELECTcolumn_name(s)FROM table1 INNERJOIN table2 ON table1.column_name = table2.column_name;
Inner Join SELECTcolumn_name(s)FROM table1 INNERJOIN table2 ON table1.column_name = table2.column_name;
Inner Join SELECTc.*, d.*FROM [Dx Codes] d inner join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID]
Alias Alias Alias SELECTd.*, e.*FROM [Dx Codes] d inner join[Encounter] eONd.[Code ID] = e.[Diagnosis ID]
Inner Join SELECTd.*, e.*FROM [Dx Codes] d inner join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID]
Inner Join No Matching 6 SELECTd.*, e.*FROM [Dx Codes] d inner join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID] 6
Inner Join SELECTd.*, e.*FROM [Dx Codes] d inner join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID] Check Total Rows in Combined & Component Tables No Match Entire Record Gone POOF!
Cross Join • Left/Right Join All of Left Table Records Listed
Cross Join • Left/Right Join All of Right Table Records Listed
Cross Join • Left/Right Join SELECTd.*, e.*FROM [Dx Codes] d right join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID]
Cross Join • Left/Right Join SELECTd.*, e.*FROM [Dx Codes] d right join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID]
SELECTd.*, e.*FROM [Dx Codes] d right join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID] • Cross Join • Left/Right Join
Cross Join • Left/Right Join SELECTd.*, e.*FROM [Dx Codes] d left join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID]
Cross Join • Left/Right Join SELECTd.*, e.*FROM [Dx Codes] d left join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID]
SELECTd.*, e.*FROM [Dx Codes] d left join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID] • Cross Join • Left/Right Join
Cross Join • Full Join All Records Listed All Records Listed
Cross Join • Full Join SELECTd.*, e.*FROM [Dx Codes] d full join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID]
Cross Join • Full Join SELECTd.*, e.*FROM [Dx Codes] d full join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID]
Cross Join • Full Join SELECTd.*, e.*FROM [Dx Codes] d full join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID]
SELECTd.*, e.*FROM [Dx Codes] d full join [Encounter] e ONd.[Code ID] = e.[Diagnosis ID] • Cross Join • Full Join
Cross Join • Cross Join All Possible Combinations Without any Restrictions
Cross Join • Cross Join SELECTd.*, e.*FROM [Dx Codes] d cross join [Encounter] e ON d.[Code ID] = e.[Diagnosis ID]
SELECTd.*, e.*FROM [Dx Codes] d cross join [Encounter] e • Cross Join • Cross Join
SELECTd.*, e.*FROM [Dx Codes] d cross join [Encounter] e • Cross Join • Cross Join
SELECTd.*, e.*FROM [Dx Codes] d cross join [Encounter] e • Cross Join • Cross Join
Cross Join • Cross Join All Possible Combinations Lots of Data