number | time
421112233444 | 1304010250
421112233444 | 1304272979 421001122333 | 1303563263 421112233444 | 1300217115 421001122333 | 1303649310i need to return unique first row with lowest number from second row, like this:
421112233444 | 1300217115
421001122333 | 1303563263any idea?
i try SELECT ph.number, mo.time from (select distinct(number) from table) ph, table mo where mo.number = ph.number;
but it returns both uniques:
421112233444 | 1304010250
421112233444 | 1304272979 421001122333 | 1303563263 421112233444 | 13开发者_Go百科00217115 421001122333 | 1303649310You can use the GROUP BY to do this:
SELECT number, MIN(time)
FROM table
GROUP BY number
ORDER BY number DESC
LIMIT 2
SELECT ph.number, min(mo.time) from (select distinct(number) from table) ph, table mo group by ph.number
精彩评论