目前分類:mysql (2)
- May 19 Fri 2017 23:01
SQL不重複取得最大筆資料與合併欄位
- Apr 15 Fri 2016 16:06
mysql group by 兩筆資料取最新筆資料
SELECT * FROM table as t1
left join table2 as t2
on t1.id = t2.t1_id
where t2.time = (SELECT max(time) from table2 as t22
where t22.t1_id=t1.id);
參考資料:
http://dev.mysql.com/doc/refman/5.7/en/example-maximum-column-group.html