我的受训者已经创建了一个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错误(未执行)。
如果他把"表"在xxx"重新格式化表"之后,执行请求:
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来链接表,我必须向他解释它太baaaad)但我问我为什么MySQL只在其他表之后才执行请求(SELECT * FROM ... UNION SELECT * FROM ...)?
感谢您的回复:)
答案 0 :(得分:0)
删除As关键字并尝试
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