我有两个表,可以说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