Question: 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...

Answer: 
```
SELECT *
  FROM books as B
 INNER JOIN books_users as BU1
    ON BU1.book_id = B.id
 INNER JOIN books_users as BU2
    ON BU2.book_id = B.id
 WHERE B.user_count = 2
   AND BU1.user_id = 3
   AND BU2.user_id = 18

```
I don't have idea about user\_count column.

This gives books which are used either by 3 or 18 

```
SELECT *
FROM books as Book
INNER JOIN books_users as BookUser
    ON BookUser.book_id = Book.id
WHERE
    Book.user_count = 2 AND
    BookUser.user_id IN  (3,18) 

```

or

```
SELECT *
FROM books as Book
INNER JOIN books_users as BookUser
    ON BookUser.book_id = Book.id
WHERE
    Book.user_count = 2 AND
    (BookUser.user_id = 3 OR BookUser.user_id = 18)

```

Edit: This gives books used by both 3 and 18.

```
SELECT book.*
FROM books as Book
INNER JOIN books_users as BookUser1
    ON BookUser1.book_id = Book.id
INNER JOIN books_users as BookUser2
    ON BookUser2.book_id = Book.id
WHERE
    Book.user_count = 2 AND
    BookUser1.user_id = 3 AND
    BookUser2.user_id = 18

```