From c319d046fb5ac828bfade2cb1399ede53cad5968 Mon Sep 17 00:00:00 2001 From: Leen Zien Date: Mon, 17 Mar 2025 14:04:44 +0100 Subject: [PATCH] solve the lab --- queries.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/queries.md b/queries.md index b06f900..5c9209e 100644 --- a/queries.md +++ b/queries.md @@ -6,33 +6,35 @@ 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 books.title, authors.name +FROM books +INNER JOIN authors ON books.author_id = authors.id; +
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 authors.name, books.title +FROM authors +LEFT JOIN books ON authors.id = books.author_id;
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 books.title, authors.name +FROM books +RIGHT JOIN authors ON books.author_id = authors.id; +
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 books.title, authors.name +FROM books +FULL JOIN authors ON books.author_id = authors.id;