SQL execute other search upon 0 results?

I have 2 separate queries one to check if there is a match and seconds for when the first has returned 0 results.

How can I combine those 2 into some like this.

If first query returns 0 results run second one. All this with one call to DB.

I am very new to all this SQL stuff.

why?? what’s wrong with 2 calls to the database?

that way, the IF is where it belongs, in the application layer

try to do it with SQL and you’ll only end up with messy SQL

I would like to decrease lode time and not double dip.

Could you give me an example please?

putting the IF into the application layer means that sometimes you will run only one query, and sometimes two

embedding the logic into SQL will likely mean a complex query that will probably run as slowly as both queries combined

please do not fall victim to premature optimization

an example of what?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.