0% found this document useful (0 votes)
2 views15 pages

SQL Basic

The document outlines different types of SQL joins including INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, and SELF JOIN, explaining when to use each type with examples. It emphasizes the importance of choosing the right join for specific use cases to write efficient SQL queries. Additionally, it notes that understanding these joins is a common interview topic.

Uploaded by

Faran khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

SQL Basic

The document outlines different types of SQL joins including INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, and SELF JOIN, explaining when to use each type with examples. It emphasizes the importance of choosing the right join for specific use cases to write efficient SQL queries. Additionally, it notes that understanding these joins is a common interview topic.

Uploaded by

Faran khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

SQL Joins

Sai Kumar Bysani


1. 𝐈𝐍𝐍𝐄𝐑 𝐉𝐎𝐈𝐍
When to use: When you need to retrieve records that have
matching values in both tables.

Example: Finding customers who have placed orders.


2. LEFT JOIN
When to use: When you need all records from the left table and
the matched records from the right table. Unmatched records from
the right table will be NULL.

Example: Find all customers, including those who haven't placed


any orders.
3. RIGHT JOIN
When to use: When you need all records from the right table and
the matched records from the left table. Unmatched records from
the left table will be NULL.

Example: Listing all orders and the customers who placed them, if
any.
4. FULL JOIN
When to use: When you need all records when there is a match in
either the left or right table. Records with no match will have NULLs

Example: Finding all customers and all orders, including those


without matches.
5. CROSS JOIN
When to use: When you need to return the Cartesian product of
the two tables. Be cautious as this can result in a large number of
rows.

Example: Pairing each customer with every product.


6. SELF JOIN
When to use: When you need to join a table with itself to compare
rows within the same table.

Example: Finding pairs of employees who have the same manager.


Choosing the right join depends
on your specific use case.
Understanding these joins and
when to use which JOIN will help
you write more efficient and
effective SQL queries.

This is also one of the most asked


interview questions!
If you found this helpful...

👍 React
💬 Comment
♻️ Share

Sai Kumar Bysani

You might also like