Reputation: 1606
If I have the following query:
SELECT, cat_name, cat_id, cat_url_title, cat_image, cat_order
FROM exp_categories
WHERE parent_id = '1'
ORDER BY cat_order
and 'cat_id' returns the following:
3,4,5,6
Is it possible to run a sub query to check on each loop if the 'cat_id
' that's returned is in the 'parent_id
' column at all? I simply want to return a '0' or '1' or 'y' or 'no'.
Upvotes: 0
Views: 37
Reputation: 780851
Use a LEFT JOIN
with 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
Upvotes: 1