左外连接到生成的表?

发布于 2024-12-25 02:40:29 字数 656 浏览 4 评论 0原文

我的方针完全错误吗? 我想对从 2 个表生成的查询进行左外连接,但我不断收到错误。我需要不同的方法吗?

t1:

ID, Surname,Firstname

t2:

ID,JobNo,Confirmed

我有以下查询:

SELECT JobNo AS N, StaffID AS P, Confirmed as C, 
       FirstName AS F,Surname AS S 
FROM gigs_players, Players 
WHERE t1.StaffID=t2.StaffID AND JobNo="2" 
      AND (`Confirmed` IS NULL OR Confirmed ='Y' ) 
ORDER BY Instrument,Surname

我想添加:

LEFT OUTER JOIN contacted (ON t1.StaffID=contact.ID AND t2.JobNo=contact.JobNo)"

我可以对从 2 个表生成的查询执行左外连接吗?

Am I on completely the wrong tack ?
I want to do a left outer join to a query generated from 2 tables , but i keep getting errors. Do I need a different approach?

t1:

ID, Surname,Firstname

t2:

ID,JobNo,Confirmed

I have the following query:

SELECT JobNo AS N, StaffID AS P, Confirmed as C, 
       FirstName AS F,Surname AS S 
FROM gigs_players, Players 
WHERE t1.StaffID=t2.StaffID AND JobNo="2" 
      AND (`Confirmed` IS NULL OR Confirmed ='Y' ) 
ORDER BY Instrument,Surname

I want to add:

LEFT OUTER JOIN contacted (ON t1.StaffID=contact.ID AND t2.JobNo=contact.JobNo)"

Can I do a left outer join to a query generated from 2 tables ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那请放手 2025-01-01 02:40:29

为了在要添加的左外连接中使用 t1t2,您需要将它们与第一个表连接,您不能直接在左外连接,如下所示:

SELECT JobNo AS N, StaffID AS P, Confirmed as C, 
   FirstName AS F,Surname AS S 
FROM gigs_players, Players
Inner join t1 on ...
Inner join t2 on ...
LEFT OUTER JOIN contacted c 
     on t1.StaffID=c.ID AND t2.JobNo = c.JobNo
WHERE t1.StaffID=t2.StaffID AND JobNo="2" 
    AND (`Confirmed` IS NULL OR Confirmed ='Y' ) 
ORDER BY Instrument,Surname

因此,根据表的结构,定义与其他表的 t1t2 的两个连接的条件。

In order to use the t1 and t2 in the left outer join that you want to add you need to join them with the first tables, you can't reference them directly in the left outer join you, Something like the following:

SELECT JobNo AS N, StaffID AS P, Confirmed as C, 
   FirstName AS F,Surname AS S 
FROM gigs_players, Players
Inner join t1 on ...
Inner join t2 on ...
LEFT OUTER JOIN contacted c 
     on t1.StaffID=c.ID AND t2.JobNo = c.JobNo
WHERE t1.StaffID=t2.StaffID AND JobNo="2" 
    AND (`Confirmed` IS NULL OR Confirmed ='Y' ) 
ORDER BY Instrument,Surname

So, based in your tables' structure, define the conditions of the two joins with t1 and t2 with other tables.

浸婚纱 2025-01-01 02:40:29

以下是子查询的左连接示例。这可能就是您正在寻找的。

select 
parts.id, 
min(inv2.id) as nextFIFOitemid 
from test.parts 
left join 
( select 
  inventory.id, 
  coalesce(parts.id, 1) as partid 
  from test.inventory 
  left join test.parts 
  on (parts.id = inventory.partid) 
) inv2 
on (parts.id = inv2.partid) 
group by parts.id;

Here is the an example of a left join to a sub query. This might be what you are looking for.

select 
parts.id, 
min(inv2.id) as nextFIFOitemid 
from test.parts 
left join 
( select 
  inventory.id, 
  coalesce(parts.id, 1) as partid 
  from test.inventory 
  left join test.parts 
  on (parts.id = inventory.partid) 
) inv2 
on (parts.id = inv2.partid) 
group by parts.id;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文