MySQL全内连接

发布于 2024-11-06 02:56:06 字数 435 浏览 3 评论 0原文

SELECT clientReport.id 
FROM clientReport 
LEFT JOIN report02 ON (report02.id = clientReport.id)
WHERE report02.id is null;

这样做相当于

SELECT clientReport.id
WHERE clientReport.rowNumber NOT EXISTS (
SELECT clientReport.rowNumber FROM report02, clientReport
WHERE report02.id=clientReport.id);

我需要一个完整的内部联接,以便在 report02 中也获得不匹配,而不仅仅是 clientReport。我该如何编写连接来做到这一点?

I have

SELECT clientReport.id 
FROM clientReport 
LEFT JOIN report02 ON (report02.id = clientReport.id)
WHERE report02.id is null;

that does the equivalent of

SELECT clientReport.id
WHERE clientReport.rowNumber NOT EXISTS (
SELECT clientReport.rowNumber FROM report02, clientReport
WHERE report02.id=clientReport.id);

I need, presumably, a full inner join to also get mismatches in report02, not just clientReport. How do I write the join to do this?

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

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

发布评论

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

评论(1

梦初启 2024-11-13 02:56:06

下面的应该可以工作。

SELECT clientReport.id,report02.id
FROM clientReport 
FULL OUTER JOIN report02 ON (report02.id = clientReport.id)
WHERE report02.id is null
OR clientReport.id is null;

它应该,但事实并非如此(因为 MySQL 目前不支持 FULL OUTER JOIN。)

这更有可能起作用:

( SELECT clientReport.id  AS report01
       , report02.id      AS report02
  FROM clientReport 
  LEFT  OUTER JOIN report02
      ON (report02.id = clientReport.id)
  WHERE report02.id IS NULL
)
UNION
( SELECT clientReport.id  AS report01
       , report02.id      AS report02
  FROM clientReport 
  RIGHT OUTER JOIN report02
      ON (report02.id = clientReport.id)
  WHERE clientReport.id is null
)

The below should work.

SELECT clientReport.id,report02.id
FROM clientReport 
FULL OUTER JOIN report02 ON (report02.id = clientReport.id)
WHERE report02.id is null
OR clientReport.id is null;

It should but it doesn't (as MySQL does not currently support FULL OUTER JOIN.)

This is more likely to work:

( SELECT clientReport.id  AS report01
       , report02.id      AS report02
  FROM clientReport 
  LEFT  OUTER JOIN report02
      ON (report02.id = clientReport.id)
  WHERE report02.id IS NULL
)
UNION
( SELECT clientReport.id  AS report01
       , report02.id      AS report02
  FROM clientReport 
  RIGHT OUTER JOIN report02
      ON (report02.id = clientReport.id)
  WHERE clientReport.id is null
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文