MySQL SELECT * FROM (SELECT *...) 出错

MySQL Error with SELECT * FROM (SELECT *...)

我的实习生创建了一个 SQL 请求(使用 MySQL),例如:

SELECT xxx.*
FROM reservation r, 
     user u,
     (
          SELECT * FROM  MyTable_sauv_01
          UNION
          SELECT * FROM  MyTable_sauv_02
     ) AS xxx
WHERE r.id_user = u.id
AND   r.id = xxx.id

当他要执行这个请求时:mysql错误(未执行)。

如果他把"tables"放在它的xxx"reformatted table"之后,请求就会被执行:

SELECT xxx.*
FROM 
     (
          SELECT * FROM  MyTable_sauv_01
          UNION
          SELECT * FROM  MyTable_sauv_02
     ) AS xxx,
     reservation r, 
     user u
WHERE r.id_user = u.id
AND   r.id = xxx.id

我知道这个请求没有很好地实现(他必须使用 JOIN 到 link 表,我必须向他解释这太糟糕了)但我问我为什么 MySQL 执行仅当其他表在 (SELECT * FROM ... UNION SELECT * FROM ...) ?

之后请求

感谢您的回复:)

删除作为关键字并尝试,

SELECT xxx.*
FROM 
     (
          SELECT * FROM  MyTable_sauv_01
          UNION
          SELECT * FROM  MyTable_sauv_02
     ) xxx,
     reservation r, 
     user u
WHERE r.id_user = u.id
AND   r.id = xxx.id