[英]Oracle Statement for outer join
I have two tables: 我有两个表:
I need to join the two tables together, but the UserProfile table won't necessary be present for each Module entry. 我需要将两个表连接在一起,但是对于每个模块条目,都不必存在UserProfile表。 I will be passed the two variables ModuleSectionID, and UserID. 我将传递两个变量ModuleSectionID和UserID。 These will help narrow down results in the final set. 这些将有助于缩小最终结果的范围。
The desired result should something like this 期望的结果应该是这样的
M.ModuleID, M.ModuleData, M.ModuleSection, U.UserProfileID, U.UserID, U.ModuleID
---------------------------------------------------------------------------------
13 "DataData" 3 1 132 13
12 "Data2Data2" 3 Null Null Null
15 "Data3Data3" 3 3 132 15
Use: 采用:
SELECT m.moduleid,
m.moduledata,
m.modulesection,
up.upserprofileid,
up.userid,
up.moduleid
FROM MODULE m
LEFT JOIN USERPROFILE up ON up.moduleid = m.moduleid
AND up.userid = IN_USERID
WHERE m.modulesection = IN_MODULESECTIONID
The IN_USERID
and IN_MODULESECTIONID
represent the variables you want to supply to the query. IN_USERID
和IN_MODULESECTIONID
表示要提供给查询的变量。
Try this: 尝试这个:
SELECT M.ModuleID, M.ModuleData, M.ModuleSectionID, U.UserProfileID, U.UserID, U.ModuleID
FROM Module m, UserProfile u
WHERE M.ModuleSctionID = <MODULE_SECTIONID_PARAMETER>
AND M.ModuleID = U.ModuleID(+)
AND <USER_ID_PARAMETER> = U.UserID (+)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.