5
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 by user_follow_category.to
.
What I want to do is: select all categories (table category
), but identify the ones being followed by user "x" in the 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
Updating
table Category
id nome imagem (que ilustra a categoria na App)
1 futebol futebol.jpg
2 tenis tenis.jpg
3 box box.jpg
table user_follow_category
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 user "74" follow?), something like:
id nome segue (ou alguma outra representação)
1 futebol sim
2 tenis sim
3 box nao
Welcome to Stackoverflow Mario. First what database system do you use? Mysql, Sqlserver? Second what is your problem?
– Jorge B.
Thank you. I use Mysql. My problem is I cannot recover all data from the "Category" table and identify which data is in the "user_follow_category" table, but which belong to the "x" user".
– Trioblack