Multiple Joins

Joins are fundamental to SQL, as they enable us to combine rows from two or more tables based on related columns. Several types of joins exist, including INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.

In real-world scenarios, finding database schemas with multiple tables linked through relationships is common. In such cases, we often need to write SQL queries with multiple joins to fetch the required data.

For instance, consider a database for a bookstore with three tables: Books, Authors, and Publishers. If we want to get a list of books along with their author names and publishers, you would require multiple joins.

SELECT Books.title, Authors.name, Publishers.name

FROM Books

INNER JOIN Authors ON Books.author_id = Authors.id

INNER JOIN Publishers ON Books.publisher_id = Publishers.id

1 comment

Leave a comment