I have two tables:
category
--------
id | nome | imagem
user_follow_category
--------------------
id | from | to | date
Note: The relationship of the two tables is given by category.id
and user_follow_category.to
.
What I want is to: select all categories (table category
), but identify the ones that are being followed by user "x" in table user_follow_category
.
This is my query:
SELECT c.id, nome, image, u.id AS follow
FROM category AS c LEFT JOIN user_follow_category as u ON c.id = u.to
WHERE u.from = 74
Update
table category
id nome imagem (que ilustra a categoria na App)
1 futebol futebol.jpg
2 tenis tenis.jpg
3 box box.jpg
user_follow_category table
id from (id do usuário) to (id da categoria)
1 74 2
2 74 1
3 62 3
I want to get the following (what categories does "74" follow?), something like:
id nome segue (ou alguma outra representação)
1 futebol sim
2 tenis sim
3 box nao