As the title suggest i want to find similar books based on customer purchased books based on the meta keywords. Below query works but Ive been told this can be simplified.
<
You can do this with joins:
select bmk2.book
from customer_books cb
inner join book_meta_keyword bmk1
on bmk1.book = cb.book
inner join book_meta_keyword bmk2
on bmk2.meta_keyword = bmk1.meta_keyword
and bmk2.book <> bmk1.book
where cb.customer = 1
The query starts from books that customer 1 purchased, then bring the corresponding keywords, and finally get all other books that have any keyword in common.
Notes:
If there are several matching keywords across books, then you will get duplicate in the resultset. In that case use select distinct
You don't need table book
to get the result you want - if needed for some reason, you can bring it with one more join