简体   繁体   English

同一请求中的多个外部联接

[英]Multiple outer join in the same request

I want to do a multiple outer join on a table with 3 others. 我想在一个桌子上与另外3个人进行多外连接。 The join is niddeclaration. 加入是niddeclaration。 The goal is to obtain a declaration with everything in relationship with it in my schema. 目标是在我的模式中获取与其相关的所有内容的声明。 The existing code did one outer join with the old syntax : where Ax= Bx (+). 现有代码使用旧语法执行一个外连接:其中Ax = Bx(+)。 The 'new ' syntax left outer join seems to do exactly the same. 左外连接的'新'语法似乎完全相同。 My problem is to use it multiple times in the same request. 我的问题是在同一个请求中多次使用它。 It seems that I can't use a unique 'declaration d' identifier, that's why I use 3 differents to do the same thing instead of one. 似乎我不能使用唯一的'声明'标识符,这就是为什么我使用3个不同的东西来做同样的事情而不是一个。

select * 
  FROM entreprise e, 
       calendrier m, 
       statut s, 
       lignedeclaration l, 
       categoriedeclaration c, 
       declaration d left OUTER JOIN saisiecategoriedeclaration sc on d.niddeclaration = sc.niddeclaration ,
       declaration de left OUTER JOIN saisielignedeclaration sl on de.niddeclaration = sl.niddeclaration,
       declaration dl left OUTER JOIN reglement r on dl.niddeclaration = r.niddeclaration
 WHERE (d.nidentreprise = e.nidentreprise) 
   AND d.niddeclaration = 12314689 
   and de.niddeclaration = 12314689 
   and dl.niddeclaration = 12314689;

In brief I want to do 2 normal join and 3 outer join in the same request. 简而言之,我想在同一个请求中做2个普通连接和3个外连接。 With the 3 outer join with the same 'left' table. 使用3个外部联接具有相同的“左”表。

You don't need to re-include declaration . 您不需要重新包含declaration

declaration d
left OUTER JOIN saisiecategoriedeclaration sc on d.niddeclaration = sc.niddeclaration
left OUTER JOIN saisielignedeclaration sl on d.niddeclaration = sl.niddeclaration
left OUTER JOIN reglement r on d.niddeclaration = r.niddeclaration

Note the omission of the commas. 请注意省略逗号。 You may also need to re-write the other tables in the query to use the modern join syntax, I'm not sure what happens if you try to mix the syntaxes. 您可能还需要重新编写查询中的其他表以使用现代连接语法,我不确定如果您尝试混合语法会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM