如果我有以下查询:
SELECT, cat_name, cat_id, cat_url_title, cat_image, cat_order
FROM exp_categories
WHERE parent_id = '1'
ORDER BY cat_order
和'cat_id'返回以下内容:
-3,4,5,6-
如果返回的“cat_id
”完全位于“parent_id
”列中,是否可以运行子查询来检查每个循环?我只想返回'0'或'1'或'y'或'no'。
答案 0 :(得分:1)
LEFT JOIN
与FIND_IN_SET
SELECT a.cat_name, a.cat_id, a.cat_url_title, a.cat_image, a.cat_order,
MAX(b.parent_id IS NOT NULL) AS cat_in_parent
FROM exp_categories AS a
LEFT JOIN exp_categories AS b ON FIND_IN_SET(b.parent_id, a.cat_id)
GROUP BY a.cat_name
ORDER BY cat_order