srikotesh
asked on
if my query returns empty i want to display input as output
Hi Expets,
query:
=======
select ci_id from category where parent_id =236282
UNION
select ci_id from category where parent_id in(select category_id from
category where parent_id=236282)
the above query some times it will returns empty
i want to display 236282 as the output if my query returns empty
can some one help me how to do it.
query:
=======
select ci_id from category where parent_id =236282
UNION
select ci_id from category where parent_id in(select category_id from
category where parent_id=236282)
the above query some times it will returns empty
i want to display 236282 as the output if my query returns empty
can some one help me how to do it.
Try
select isnull(ltrim(ci_id),'236282') from
(select ci_id from category where parent_id =236282
UNION
select ci_id from category where parent_id in(select category_id from
category where parent_id=236282)) a
ASKER
hi HuaMinChen,
the above query is not working
the above query is not working
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got the solution for this query.
SELECT * FROM category WHERE parent_id = 236282 OR parent_id IN ( SELECT category_id FROM category WHERE parent_id = 236282 );
SELECT * FROM category WHERE parent_id = 236282 OR parent_id IN ( SELECT category_id FROM category WHERE parent_id = 236282 );
which lists all children and grandchildren of the given id (same as the query you posted originally)
not sure about this : "i want to display 236282 as the output if my query returns empty" or what you actually wanted in the first place
good for you if you got it working
ps : you can accept your own answer if you don't want to spend your points
not sure about this : "i want to display 236282 as the output if my query returns empty" or what you actually wanted in the first place
good for you if you got it working
ps : you can accept your own answer if you don't want to spend your points
ASKER
Hi skullnobrains,
i am getting the expected result from the second query as u posted
THANKS
i am getting the expected result from the second query as u posted
THANKS
ASKER
Thanks,but it is too late
Please look into my new question posted recently.
https://www.experts-exchange.com/questions/28729520/how-do-i-modify-this-mysql-query.html
https://www.experts-exchange.com/questions/28732500/how-to-get-the-count-query-from-the-below-query.html
Please look into my new question posted recently.
https://www.experts-exchange.com/questions/28729520/how-do-i-modify-this-mysql-query.html
https://www.experts-exchange.com/questions/28732500/how-to-get-the-count-query-from-the-below-query.html
Open in new window