If you do not want bar
return to where foo
returns entries, try:
select foo from TABLE where foo like '%foo%' union all select bar from TABLE where bar like '%foo%' and not exists (select null from TABLE where foo like '%foo%')
Alternatively, the version without merging:
select case when foo like '%foo%' then foo else bar end as foobar where foo like '%foo%' or (bar like '%foo%' and not exists (select null from TABLE where foo like '%foo%'))
source share