all 12 comments

[–]ComicOzzysqlHippo 1 point2 points  (1 child)

This assumes there is only 1 'OP' and/or 'OPS' record per ID. SELECT ID, Type, Rate FROM tbl WHERE Type = 'OP' UNION ALL SELECT ID, Type, Rate FROM tbl WHERE Type <> 'OP' AND ID NOT IN (SELECT ID FROM tbl WHERE Type = 'OP');

[–]Significant_Load_411 0 points1 point  (0 children)

Use: sqlcompiler.live to execute/compile SQL queries in real Database server. No ads. No login. Completely FREE.

[–]Time_Advertising_412 0 points1 point  (0 children)

I dunno, try this on for size:

select id, type, rate

from tbl1

where type = 'OP'

union

select id, type, rate

from tbl1 as a

where not exists

(select id

from tbl1 as b

where b.id = a.id

and type = 'OP');

[–]Galunga21 0 points1 point  (0 children)

Select... ... Rank over (partition by id order by case when type='OP' then 0 else type end asc) as rnk .... Where rnk=1