摆脱重复的行

时间:2017-02-13 17:59:01

标签: sql oracle oracle11g

我有以下查询返回重复的行,如何摆脱它们:

select a.code, b.daytime, b.created_date 
from ov a, CURVE b 
where b.curve_object_id = a.object_id 
order by b.daytime

我正在寻找的是从第二个表中提取对象名称(在我的情况下是它的代码)的最佳方法,其中object_id在两个表中相同?

2 个答案:

答案 0 :(得分:0)

您是否尝试group by消除重复的行,如下所示?

select a.code, b.daytime,b.created_date 
    from ov a, CURVE b 
    where b.curve_object_id=a.object_id 
    group by a.code, b.daytime,b.created_date 
    order by b.daytime

答案 1 :(得分:0)

始终使用现代显式JOIN语法。

也就是说,您可以在选择中使用distinct

select distinct a.code,
    b.daytime,
    b.created_date
from ov a
join CURVE b on b.curve_object_id = a.object_id
order by daytime