I need to relate data according to the last item found in the user table, for example:
Table_A:
+----------------+-------------+
| user_id | title_id |
+----------------+-------------+
| 154138746 | 123 |
+----------------+-------------+
Table_B
+----------------+----------------------+
| title_id | genres |
+----------------+----------------------+
| 123 | Ação, Aventura, Drama|
+----------------+----------------------+
| 122 | Drama, Sci-fi |
+----------------+----------------------+
| 126 | Romance, Aventura |
+----------------+----------------------+
| 135 | Ação , Drama |
+----------------+----------------------+
What I need is to do a SELECT on table A by retrieving their respective data in table B, and then using such data retrieve from the same table B its similar based on the category, it is possible to do everything in a query or is better share?
I'd prefer the query to return only the semanual values found in table_B, ignoring the others that were used only as parameters for the search.
I'm trying with the following query:
SELECT wt.user_id, wt.title_id,
fl.id, fl.genres,
sm.*
FROM watchedtitles wt
INNER JOIN filmes fl
ON wt.title_id = fl.id
LEFT JOIN filmes sm
ON FIND_IN_SET(SUBSTRING_INDEX(fl.genres, ',', 1), fl.genres)
In the case of the subtitles, it is my table_A from where I will get the last item that the user watched and then look at the table_B movies, their similar ones, however when using SUBSTRING_INDEX I am limited to having to type each time a separate index. Keeping in mind that the genres column is a string containing the comma separated categories, how would such a query be possible?