0

我有许多在 MySQL 4 下运行的 MySQL 语句,但不是 MySQL 5。这些语句结合了 UNION 和 JOIN。

为了简化 MySQL 语句,我得出以下在 MySQL 4 下运行但不在 MySQL 5 下运行的语句:

SELECT
  bteamres.rank AS `rank`
FROM
  bteamres
    LEFT OUTER JOIN (btourn AS tourn) ON (bteamres.tourncode=tourn.tourncode)
WHERE
  (bteamres.nofivb1=100427)

UNION

SELECT
  bteamres.rank AS `rank`
FROM
  bteamres
    LEFT OUTER JOIN (btourn AS tourn) ON (bteamres.tourncode=tourn.tourncode)
WHERE
  (BTEAMRES.NOFIVB2=100427)

我收到的错误代码是:

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON     (bteamres.tourncode=tourn.tourncode)
WHERE
  (BTEAMRES.NOFIVB2=100427)' at line 15

如果我删除连接,请求在 MySQL 4 和 MySQL 5 上都可以正常工作。我知道 MySQL 4 和 MySQL 5 之间存在一些语法差异,但我看不出如何使这个语句工作。

感谢您的帮助。帕特里克

4

1 回答 1

1

LEFT JOIN我认为问题在于ed 表周围的括号:

  • LEFT JOIN (btourn AS tourn)触发错误
  • LEFT JOIN btourn AS tourn被接受

您可以在这里尝试(我不得不将联合包装到一个选择中以避免 sqlfiddle 的错误): http ://sqlfiddle.com/#!2/d4885/11

SELECT bteamres.rank AS `rank`
FROM      bteamres
LEFT JOIN btourn AS tourn ON bteamres.tourncode=tourn.tourncode
WHERE bteamres.nofivb1=100427

UNION 

SELECT bteamres.rank AS `rank`
FROM      bteamres
LEFT JOIN btourn AS tourn ON bteamres.tourncode=tourn.tourncode
WHERE bteamres.nofivb2=100427
于 2012-06-26T14:05:39.777 回答