If a SELECT statement returns an empty result set...
Posted: Thu Aug 27, 2009 9:12 pm
Is there a way to return something else if a SELECT statement returns an empty result set? For example, I'm trying this:
if the second SELECT statement returns an empty result set, I'd like another statement to be UNIONed with the first SELECT statement. This is completely understandable right?
How do I check if a statement returned an empty result set or not? Is an empty result set just NULL or is it something else? How can I return something if the other thing is NULL, but if it isn't return the other thing (e.g. in javascript, var foo = foo || bar)?
Thanks for reading. All help is appreciated.
Code: Select all
INSERT user_referrals
SELECT $userId, $userId, 0
UNION
SELECT ancestor_id, $userId, depth+1 FROM user_referrals
WHERE descendant_id = $referralId
How do I check if a statement returned an empty result set or not? Is an empty result set just NULL or is it something else? How can I return something if the other thing is NULL, but if it isn't return the other thing (e.g. in javascript, var foo = foo || bar)?
Thanks for reading. All help is appreciated.