Skip to content

lab-postgres-sql-joins #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

```sql
-- Your Query Goes Here
SELECT * FROM books INNER JOIN authors ON books.author_id = authors.id;

-- also a solution:
-- SELECT books.*, authors.*
-- FROM books
-- INNER JOIN authors ON books.author_id = authors.id

```

<br>
Expand All @@ -16,6 +23,15 @@

```sql
-- Your Query Goes Here

SELECT authors.*, books.*
FROM authors
LEFT JOIN books ON authors.id = books.author_id;

-- or with just the *:
-- SELECT *
-- FROM authors
-- LEFT JOIN books ON authors.id = books.author_id;
```

<br>
Expand All @@ -24,6 +40,12 @@

```sql
-- Your Query Goes Here

SELECT *
FROM authors
RIGHT JOIN books ON authors.id = books.author_id;


```

<br>
Expand All @@ -32,6 +54,10 @@

```sql
-- Your Query Goes Here

SELECT *
FROM authors
FULL JOIN books ON authors.id = books.author_id;
```

<br>
Expand All @@ -42,6 +68,10 @@

```sql
-- Your Query Goes Here
SELECT books.title, publishers.name
AS publisher_name, publishers.location
FROM books INNER JOIN publishers ON books.publisher_id = publishers.id;

```

<br>
Expand All @@ -50,6 +80,10 @@

```sql
-- Your Query Goes Here
SELECT publishers.*, books.*
FROM publishers
LEFT JOIN books ON publishers.id = books.publisher_id;

```

<br>
Expand All @@ -58,6 +92,10 @@

```sql
-- Your Query Goes Here
SELECT books.*, publishers.name
AS publisher_name
FROM publishers
RIGHT JOIN books ON publishers.id = books.publisher_id;
```

<br>
Expand All @@ -66,6 +104,10 @@

```sql
-- Your Query Goes Here
SELECT *
FROM books
FULL JOIN authors ON books.author_id = authors.id
FULL JOIN publishers ON books.publisher_id = publishers.id;
```

<br>