suppose an object can have multiple tids
now suppose I do this query:
SELECT n.nid, t.tid, GROUP_CONCAT(t.tid)
FROM node n JOIN term_node t ON t.nid = n.nid
GROUP BY n.nid
HAVING t.tid = 31;
In which I want to fetch entries in table node that has tid = 31…but then I also want a list of all the tids corresponding to that row (hence the GROUP_CONCAT) even if they are not 31
Using WHERE t.tid = 31 will leave out the tids that are not 31 from the GROUP concat
and using HAVING t.tid = 31 will leave out rows in which the tid column that appears in the GROUPed row is not 31
Either way has the potential to make the GROUP_CONCAT list incomplete or the rows of nodes with at least one tid = 31 incomplete
Is there a way to resolve this such that I am guaranteed to get ALL the nodes in which the node has at least one tid association equals to 31 AND that GROUP_CONCAT will list ALL The list of tids associated with that node?
This would probably be better as 2 queries. GROUP_CONCAT has a limitation on how long the resulting string can be anyways, so it is not reliable unless you know you will always be under the string length limit.
I would run the first query ‘WHERE tid = 31’, then run a separate query to get all other ids afterwards and combine in code.