Professional Documents
Culture Documents
SQ L Presentation
SQ L Presentation
Limited
SQL JOINS
Presented by
Venugopal
AGENDA
• Introduction to joins
• What are joins in SQL
• Types of joins
• Difference between sub queries and joins
• Analyzation of performance
• Code and explanation
• Practical session
• Joins with three tables
• Conclusion
Introduction to joins
• Joins in SQL which are used to combined rows from two or more tables,
based on related column between those two tables. They predominantly
used when a user is trying to extract data from tables, which have one-to-
many or many-to-many relationship between them.
• SELECT w.Worker_ID,w.FIRST_NAME,b.BONUS_AMOUNT,
b.WORKER_ID from Worker w JOIN Bonus b
• ON w.WORKER_ID=b.WORKER_ID;
• =
What are joins in SQL
• Mainly these can be performed • Cross join
• Self join
• Natural join
Types of joins
• Inner join • Outer join
• SELECT w.Worker_ID,w.FIRST_NAME,b.BONUS_AMOUNT,b.WORKER_ID • SELECT w.Worker_ID, w.FIRST_NAME, b.BONUS_AMOUNT, b.WORKER_ID
from Worker w inner JOIN Bonus b ON w.WORKER_ID=b.WORKER_ID; from Worker w full JOIN Bonus b ON w.WORKER_ID=b.WORKER_ID
Continues…
• Left join • Right join
• SELECT w.Worker_ID, w.FIRST_NAME, b.BONUS_AMOUNT, • SELECT w.Worker_ID, w.FIRST_NAME, b.BONUS_AMOUNT, b.WORKER_ID
b.WORKER_ID from Worker w left JOIN Bonus ON from Worker w right JOIN Bonus b ON w.WORKER_ID=b.WORKER_ID
w.WORKER_ID=b.WORKER_ID
Continues…
• Cartesian Product
Difference between natural and inner joins
Self join
• SELECT *
FROM worker w
INNER JOIN bonus b ON w.worker_Id = b.worker_Id
INNER JOIN title t ON b.worker_Id = t.Worker_ref_id
Join with three table
Conclusion
• Readability
• Writability
• Performance
Thank you