我有兩個表,可以說table1和table2具有公共列id和update_date。我正在尋找基於最新的update_date降序的ID和update_date。我一起使用'union'和'order by',它們以update_date的降序給出了結果,但是有重複的id,我不知道如何去除。在使用UNION和ORDER的mysql查詢中避免重複
我的查詢是什麼樣子,
(select id,update_date from table1 where [condition])
UNION
(select id,update_date from table2 where [condition])
order by update_date desc;
我可以得到由(上述查詢),作爲臨時選擇加入不同的ID去掉重複的ID的;但問題是我也需要update_date。
任何人都可以建議如何擺脫重複,仍然得到id和update_date信息。
我希望這下面的鏈接可能會有所幫助。 http://stackoverflow.com/questions/7640396/removing-duplicate-results-while-using-union-select – GoutamS 2016-12-21 12:52:18