0
存在我有两个表:categories
和prodvscats
检查是否匹配的记录在连接表
categories prodvscats
id | id
title | categories_id
每个表都有例如一些行:
categories prodvscats
categ1 | categ1
categ2 | categ2
categ3
categ4
我想回到所有类别,但我想知道prodvscats
表中有哪些存在。
期望的结果:
title boolean variable exists
categ1 | 1
categ2 | 1
categ3 | 0
categ4 | 0
我试着用join
但它只返回前两排。也许它需要像案例一样的东西,但我不知道该怎么做。
SELECT categories.id, categories.title
FROM categories
INNER JOIN prodvscats ON prodvscats.categories_id = categories.id
ORDER BY id