postgresql - Sql subselect improvement through joins? -
how can improve following query think missing , can done better :( have table , one-to-many b want info , row b linked highest sequence number. came this:
select a.*, ( select b.value b a.idb = b.id order b.seqnr desc limit 1 )
performance important me, best bet ?
that's best bet, if visiting small number of rows , b.
if going covering rows anyway, can try address problem window aggregations assigning row numbers rows b:
select * ( select a.*, b.*, row_number() over(partition b.id order b.seqnr desc) seqidx join b on a.idb = b.id ) seqidx = 1
this use lot of temp space though... consider getting , b primary keys out of aggregate , joining onto them later (it's not clear query pkey columns are, since b.id apparently isn't)
Comments
Post a Comment