Hello all,
I have an issue with data.
Asset_Image:
id | filename
-----------------
1 | john.jpg
2 | steve.jpg
Asset_Client
id | client_id | asset_id
-------------------------
1 | 1 | 1
-------------------------
2 | 2 | 1
-------------------------
3 | 1 | 2
-------------------------
4 | 2 | 2
-------------------------
5 | 3 | 2
-------------------------
I need todo a query like:
This should return both asset_id 1 and 2
However I need todo something like
Which should only return Asset_Image with the id of 2
I can paste queries I've tried but I think they are rather silly and dont work so...note attachment_id = asset_id
Code MySQL:SELECT * FROM Asset_Image as d WHERE `enabled` = 1 AND id in (select attachment_id from (select ac.attachment_id, GROUP_CONCAT(ac.client_id ORDER BY ac.client_id) as con from Asset_Client as ac where ac.enabled = 1 AND ac.attachment_type = 'image' GROUP BY ac.attachment_id HAVING con = '1,4') as filtered) AND d.`status` != 3 ORDER BY d.id DESC LIMIT 0, 100
However If I query for client_id 1 and 2, I dont get asset id of 2


Reply With Quote




Bookmarks