I'm not sure if this is the best thing to do in all occasions, but I have found a great speed increase using unions over group by.

select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 = ( select min(seq1) from mytable);
union
select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 = ( select min(seq1) from mytable);
order by fkey, uid, seq2;

the union clause with remove your duplicates for you as you were doing with your group by.

using min on large tables can cause problems. you may want to do your select min(seq1) from mytable or even have a trigger function after insert/update that checks the new value against the current lowest stored in another table.

not sure if this helps, but i hope it does.

russ



---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Reply via email to