Query construction question case|coalesce|other

Hi,

I want my query to bring back one set of results based on a priority value (a,b,c or d).
(all other values sought are standard across all records, which means the only differentiator is the priority column).

Basically bring me back priority ‘c’ if it is there and if not, bring me back priority ‘b’

I think I can only make priority ‘c’ come back as NULL, if I use a union all query structure. Should that be what I do or is there a more efficient CASE statement , for example.

bazz

I guess you’ll need more of an idea of what the query is like.


select id
       , name
       , priority
  from table1
where 1

so I need to bring back the results with priority ‘b’, only if there are no records for priority ‘c’.
bazz

I’m not sure I understand your need, but if you want the highest priority, and the only changing value is the priority column, you could use MAX and GROUP BY?


select 
    id
  , name
  , MAX(priority) AS priority
from table1
GROUP BY
    id
  , name

what the heck should we do about priority ‘d’ then? :confused: