srikotesh
asked on
i want to know is there any alternative for union in mysql while writing query
Hi Experts,
I want to know is there any alternative for union in mysql
i dont want to use union because this sql query i have to convert into hibernate hql query.
But hibernat hql doesn't support union.
can any one suggest alternative of union
Below is my query i want to use this query without union
query:
========
select * from category where parent_id =236282
UNION
select * from category where parent_id in(select category_id from
category where parent_id=236282)
Thanks,
I want to know is there any alternative for union in mysql
i dont want to use union because this sql query i have to convert into hibernate hql query.
But hibernat hql doesn't support union.
can any one suggest alternative of union
Below is my query i want to use this query without union
query:
========
select * from category where parent_id =236282
UNION
select * from category where parent_id in(select category_id from
category where parent_id=236282)
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent
The first solution only accounts for one level of depth, the one i posted goes as deep as is there in one query. Something to keep in mind.
hmm, the question was about only one level.. btw, as hibernate was mentioned: I would let hibernate resolve the hierarchy.
ASKER
select * from category where parent_id =236282
UNION
select * from master where parent_id =236282
in this scenario what i a have to do
OR WILL WORK ?
UNION
select * from master where parent_id =236282
in this scenario what i a have to do
OR WILL WORK ?
How can I tell? What is the content of master? How does it relate to category?
http://codepad.co/s/ac9930
or take a look at this which is close to the same thing but requires a function(see my post to this answer here: https://www.experts-exchange.com/questions/28662047/How-can-i-get-all-childs-and-parent-ids-if-i-pass-the-value-in-a-query.html) ...
Open in new window
No function, but requires you to change the ID of the child element you want all the parents of:
Open in new window