Oracle查询以避免重复 [英] Oracle query to avoid duplicates
本文介绍了Oracle查询以避免重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Team,
Hi Team,
Table1
AccNo TRNO AMOUNT
123 123 100
1234 1234 50
12345 12345 50
Table2
AccNO CODE
123 A
123 I
1234 A
12345 I
Need the O/P like below
AccNo TRNO AMOUNT
123 123 100
1234 1234 50
12345 12345 50
如上所述,需要加入2个表并获取输出。
我尝试过:
Need to join the 2 tables and fetch output as mentioned.
What I have tried:
SELECT DISTINCT(AccNo),TRNO,AMOUNT
FROM Table1 T1 JOIN
Table2 T2 ON T1.AccNo=T2.AccNo
推荐答案
好的,我能用代码找到的唯一问题是DISTINCT(AccNo)
中的AccNo
列不明确。
换句话说,Oracle无法确定您是否在Table1 <中表示
AccNo
/ code>或中的那个> Table2
。
所以让Oracle知道使用哪一个。例如。
Ok, the only problem I can find with your code is that the columnAccNo
inDISTINCT(AccNo)
is ambiguous.
In other words, Oracle cannot determine whether you meant theAccNo
inTable1
or the one inTable2
.
So just let Oracle know which one to use. E.g.
SELECT DISTINCT(T1.AccNo),TRNO,AMOUNT
这篇关于Oracle查询以避免重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文