I have a table "tanned", "commented" and "visited", every time a user likes, comments or visits a certain book on my page a record is inserted into the database for such:
Tanned table:
+----------------+-------------+
| id_livro | usuario |
+----------------+-------------+
| 1 | user_id |
+----------------+-------------+
| 4 | user_id |
+----------------+-------------+
| 1 | user_id |
+----------------+-------------+
Commented Table:
+----------------+-------------+
| id_livro | comentario |
+----------------+-------------+
| 1 | coment 1 |
+----------------+-------------+
| 7 | coment 2 |
+----------------+-------------+
| 1 | coment 3 |
+----------------+-------------+
Table visited:
+----------------+-------------+
| id_livro | usuario |
+----------------+-------------+
| 1 | user_id |
+----------------+-------------+
| 6 | user_id |
+----------------+-------------+
| 4 | user_id |
+----------------+-------------+
In the example above we see that the book with id 1
is repeated in the 3 tables and the book with id 4
is repeated in two of them, these would be 2 books that I would recommend for customers in a list because apparently they are two "popular" books, how could I organize a SELECT
to return the books so that I can organize them on the "recommended" page