sql left outer join order by column in left table but preserve all rows -
i have following:
select table1.id table1 left outer join table2 on table2.table1_id = table1.id (table1.entry_id=2) , parent_id=0 order sum(table2.column1) - sum(table2.column2)
works fine until add 'order by', need relevant rows table1, if have unmatched rows in table2, ordering place them @ bottom.
try instead:
select t1.id table1 t1 left outer join ( select table1_id, sum(column1) sum1, sum(column2) sum2 table2 group table1_id ) t2 on t2.table1_id = t.id , t1.entry_id = 2 , t1.parent_id = 0 order t2.sum1 - t2.sum2;
Comments
Post a Comment