sql oracle左连接问题 [英] sql oracle left join issue

查看:65
本文介绍了sql oracle左连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个sql查询的问题:



i有2个表,我想要table1左连接table2,任务是显示全部table1的行和每个table1的行,我搜索所有table2中的记录,直到第一个匹配的值。



所以

hi guys, i have an issue with sql query:

i have 2 tables, and i want table1 left join table2, mission is to show all table1's rows and for each table1's row, i search records in all table2 until the 1st matched value.

so

results' row number = talbe1's row number

,只需添加table2的第一个匹配值,但在这里我得到

, just add table2's 1st matched value, but here i get

results' row number >talbe1's row number

,任何帮助,plz。*

, any help, plz.*

推荐答案





查看左外连接 [ ^ ]



希望这会对你有所帮助。



干杯
Hi,

Check this Left Outer Join[^]

Hope this will help you.

Cheers


类似于:

Something like:
SELECT * FROM TableA
LEFT OUTER JOIN 
(SELECT relevantField, ROWNUMBER() OVER(PARTITON BY ID ORDER BY RelevantField2 DESC) RN
 FROM TableB) b
ON TableA.Field = TableB.Field
WHERE b.RN = 1



在不知道表格结构的情况下,你必须自己输入正确的字段名称,但想法是将ROWNUMBER添加到第二个子查询中的表允许您仅选择连接产生的第一个记录。


Without knowing the table structure, you have to put in the correct field names yourself, but the idea is that adding a ROWNUMBER to the second table in the subquery allows you to select only the first record resulting from the join.


这篇关于sql oracle左连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆