I have a couple tables that look like this:
___________ ___________ | Books | | Tags | |-----------| |-----------| | book_id | | tag_id | | book_name | | tag_name | ----------- -----------
And a join table that connects the “many-to-many relationship”:
___________ | Books/Tags| |-----------| | book_id | | tag_id | -----------
I have the following query:
SELECT book_name, tag_name FROM books
JOIN books_tags ON books.book_id = books_tags.book_id
JOIN tags ON tags.tag_id = books_tags.tag_id
WHERE books.book_id = 283
And the following (for books that aren’t tagged):
SELECT book_name FROM books WHERE books.book_id = 283
Is there a way to merge those two queries into one?
You want a LEFT join