Good day. There are three tables:
books (id, title) users (id, first_name, last_name, age) users_books (id, user_id, book_id) The users_books table contains information about books purchased by users. You must select a list of users who did not buy a book with a specific title. Can I do better than I did?
My request:
SELECT DISTINCT users.first_name, users.last_name, users.id FROM users INNER JOIN users_books 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