![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
| |||
| I have a table like so: Child Id ParentId ColumnA ColumnB What I want is a list of Child Ids such that either ColumnA or ColumnB is the max (for that column) for a given Parent Id. All columns have indicies on them. What I'm using is this: select Child.Id from child c join (select ParentId, max(ColumnA) Max_ColumnA, max(ColumnB) Max_ColumnB from Child group by ParentId) MaxValues on MaxValues.ParentId = c.ParentId where c.ColumnA = MaxValues.Max_ColumnA or c.ColumnB = MaxValues.Max_ColumnB |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |