I have the following query.
select * from (select p.*, (select 1 from alarmitems a where (a.pair = p.pair OR a