sql - Get MAX() on repeating IDs -


this how query results currently. how can max() value each unique id ?

ie,

for 5267139 8. 5267145 4  5267136 5 5267137 8 5267137 2 5267139 8 5267139 5 5267139 3 5267141 4 5267141 3 5267145 4 5267145 3 5267146 1 5267147 2 5267152 3 5267153 3 5267155 8       select distinct st.scoreid, st.scoretrackingtypeid     scoretrackingtype stt     left join scoretracking st     on stt.scoretrackingtypeid = st.scoretrackingtypeid     order st.scoreid, st.scoretrackingtypeid desc  

results

group by partition table separate blocks based on column(s) specify. can apply aggregate function (max in case) against each of blocks -- behavior applies default below syntax:

select first_column, max(second_column) max_second_column table group first_column 

edit: based on query above, looks don't need scoretrackingtype table @ all, leaving in place, use:

select st.scoreid, max(st.scoretrackingtypeid) scoretrackingtypeid scoretrackingtype stt     left join scoretracking st on stt.scoretrackingtypeid = st.scoretrackingtypeid group st.scoreid order st.scoreid 

the group by obviate need distinct, max give value looking for, , order by still apply, since there single scoretrackingtypeid value each scoreid can pull out of ordering.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -