The query:
SELECT ct_cid as level1 FROM cat_tree WHERE ct_sid=$sid_int AND ct_parent =$cid_int)
UNION (SELECT ct_cid as level2 FROM cat_tree WHERE ct_sid=$sid_int AND ct_parent IN level1)
The query is supposed to find the child nodes up to 2 levels of a tree node.
I get “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘level1)” How can I use the results of the 1st select in the 2nd select?
you don’t need parens around the second SELECT statement… Also, the field names and order must match in BOTH SQL-Select statements. What you may want is something like
Now, your other half of the question… using the results of the first… Redo the query as a sub-select in the SECOND query…
Notice the parens are only needed in the SUB-SELECT, not the UNION select. Not knowing your data, there might be an easier approach to what you are trying to get