【问题标题】:MySQL full inner joinMySQL 全内连接
【发布时间】:2011-05-11 11:45:30
【问题描述】:

我有

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。我如何编写加入来执行此操作?

【问题讨论】:

  • 编辑并添加了问题

标签: mysql sql join inner-join


【解决方案1】:

以下应该可以工作。

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
)

【讨论】:

  • MySQL 不支持完全外连接。您需要一个左连接和右连接的联合才能与 MySQL 一起使用。
猜你喜欢
  • 2011-12-20
  • 2016-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-11
  • 1970-01-01
  • 1970-01-01
  • 2012-04-21
相关资源
最近更新 更多