Is there a way to join this two queries into one?
query = "select foo from TABLE where foo like '%foo%'";
if (query.empty())
query = "select bar from TABLE where bar like '%foo%'"
Update:
select ifnull(foo,bar) from TABLE where foo like 'foo%' or bar like '%foo%';
Thanks to Kamal for the idea
For Oracle
Select NVL(foo,bar) from TABLE where foo like ‘%foo%’ or bar like ‘%foo%’;