Good time of day. There are three tables:
books (id, title)
users (id, first_name, last_name, age)
users_books (id, user_id, book_id)
The table users_books contains information about the users purchased books. You should select the list of users who did not buy a book with a certain name.
My request:
SELECT
DISTINCT users.first_name,
users.last_name,
users.id
FROM
users
Users_books INNER JOIN ON users.id = users_books.user_id
WHERE
users_books.user_id NOT IN (
SELECT
`user_id`
FROM
`users_books`
WHERE
users_books.book_id = (SELECT id FROM books where title = "Book")
)
GROUP BY
users_books.user_id
Is it possible to execute a query optimally?