diff --git a/queries.md b/queries.md index b06f900..169e358 100644 --- a/queries.md +++ b/queries.md @@ -7,7 +7,10 @@ 1. Using an **INNER JOIN**, list all books (left table) that have an assigned author (right table). The result should include only books with assigned authors. ```sql --- Your Query Goes Here +SELECT b.title, a.name +FROM books b +INNER JOIN authors a +ON b.author_id = a.id; ```
@@ -15,7 +18,10 @@ 2. Using a **LEFT JOIN**, list all authors (left table) and their corresponding books on the (right table). The result should include all authors, including those who don't have any books assigned. ```sql --- Your Query Goes Here +SELECT a.name, b.title +FROM authors a +LEFT JOIN books b +ON a.id = b.author_id; ```
@@ -23,7 +29,10 @@ 3. Using a **RIGHT JOIN**, list all books (right table) and their corresponding authors on the (left table). The result should include books without assigned authors. ```sql --- Your Query Goes Here +SELECT b.title, a.name +FROM authors a +RIGHT JOIN books b +ON a.id = b.author_id; ```
@@ -31,7 +40,10 @@ 4. Using a **FULL JOIN**, list all records from the `books` and `authors` tables. The result should include all details from both tables, even if there are no match. ```sql --- Your Query Goes Here +SELECT * +FROM authors a +FULL JOIN books b +ON b.author_id = a.id; ```
@@ -41,7 +53,10 @@ 1. Using an **INNER JOIN**, list all books (left table) and their corresponding publishers on the (right table). The result should include the book's title, publisher's name, and location. ```sql --- Your Query Goes Here +SELECT b.title, p.name, p.location +FROM books b +INNER JOIN publishers p +ON b.publisher_id = p.id; ```
@@ -49,7 +64,10 @@ 2. Using a **LEFT JOIN**, list all publishers (left table) and any books they have published on the (right table). The result should include all publishers, including those who haven't published any books. ```sql --- Your Query Goes Here +SELECT p.name, b.title +FROM publishers p +LEFT JOIN books b +ON b.publisher_id = p.id; ```
@@ -57,7 +75,10 @@ 3. Using a **RIGHT JOIN**, list all books (right table) and their corresponding publishers on the (left table). The result should include all books, even those without a linked publisher. ```sql --- Your Query Goes Here +SELECT p.name, b.title +FROM publishers p +RIGHT JOIN books b +ON b.publisher_id = p.id; ```
@@ -65,7 +86,12 @@ 4. Using a **FULL JOIN**, list all records from the `authors`, `books`, and `publishers` tables. The result should include all records from the three tables, even if there are no matches between them. ```sql --- Your Query Goes Here +SELECT * +FROM books b +FULL JOIN publishers p +ON b.publisher_id = p.id +FULL JOIN authors a +ON b.author_id = a.id; ```