I have a books , users and a books_users table.
Now, i want to get a book that is managed by me (user_id = 3) and other user(user_id = 18):
SELECT *
FROM books as Book
LEFT JOIN books_users as BookUser
ON BookUser.book_id = Book.id
WHERE
Book.user_count = 2 AND
BookUser.user_id = 3 AND
BookUser.user_id = 18
Problem:
as the left join splits the result of books in rows, it doesn’t give a row with the two users…
I believe you want to join to the BookUser table twice to get both conditions and use DISTINCT to get the book once: