【发布时间】:2012-07-06 01:24:52
【问题描述】:
我有两个表,假设 table1 和 table2 有公共列,id 和 update_date。我希望根据最新的 update_date 按降序获取 id 和 update_date。我一起使用了“union”和“order by”,结果按 update_date 的降序排列,但有重复的 id,我不知道如何摆脱。
我的查询是这样的,
(select id,update_date from table1 where [condition])
UNION
(select id,update_date from table2 where [condition])
order by update_date desc;
我可以通过将 select distinct id from (above query) 添加为 temp 来摆脱重复的 id;但问题是我也需要 update_date。
任何人都可以建议如何摆脱重复并仍然获得 id 和 update_date 信息。
【问题讨论】:
-
我希望这个下面的链接可能会有所帮助。 stackoverflow.com/questions/7640396/…