取第一次出现我有Oracle SQL查询取出由结果
select
distinct
tab1.col1,
tab2.col1
from
table1 tab1
join table2 tab2 on tab1.col1 = tab2.col1
在这里,我得到的不同的值方面的预期。
For Example : The result rows are
1 2
3 4
5 6
现在我想再为table3添加一个连接。所以我的SQL是
select
distinct
tab1.col1,
tab2.col1,
tab3.col1
from
table1 tab1
join table2 tab2 on tab1.col1 = tab2.col1
join table3 tab3 on tab1.col1 = tab3.col1
这里问题是什么是表3返回多个值。 这导致基于表3的重复行。
For Example : The result rows are
1 2 4
1 2 5
3 4 1
3 4 2
5 6 3
(在这里,如果你发现第1行& 2是重复和3 & 4是一式两份)
我所试图做的是对加入表3中我想获取的 第一次出现行。
你能给出一个表格中的数据的例子,你得到的查询结果和你想要得到的查询结果吗? – Rene 2010-07-09 07:05:15
我在 – Madhu 2010-07-09 07:10:38
上添加了预期结果您的连接条件是“tab1.col1 = tab2.col1”,但您的示例结果集包含它们的不同值... 请提供创建表语句,其中包含一些示例数据和预期结果集基于该样本数据。 – 2010-07-09 07:51:01