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