On Sat, 22 Jul 2006 09:54:29 GMT, Andrew <infoREMOVE (AT) THISmuonlab (DOT) com>
wrote:
Quote:
I have the following SQL:
select * from tblProducts where prod_name like '%example%' or
prod_description like '%example%'
How do I order the results such that the results found by the prod_name
clause come first, followed by those found by the prod_description clause?
Do i have to union two selects? Is that an efficient way of doing things? |
Not sure about efficiency, but here's another approach:
select *
from tblProducts
where prod_name like '%example%'
or prod_description like '%example%'
order by case
when prod_name like '%example%' then 1
when prod_description like '%example%' then 2
else 999 -- can't happen
end