我有以下查询:
SELECT `snap`.`ID`, `user`.`username`, `vote`.`type`
FROM (`snap`) JOIN `user` as u ON `u`.`ID` = `snap`.`user`
LEFT JOIN (select * from vote where user = "18") as vote ON `snap`.`ID` = `vote`.`snap`
JOIN (SELECT CEIL(MAX(ID)*RAND()) AS ID FROM snap)) AS x ON `snap`.`ID` => `x`.`ID`
WHERE `snap`.`active` = 0 LIMIT 1
它工作得很好,直到我添加了最后一个 JOIN。现在我得到错误:“每个派生表都必须有自己的别名”。我知道这是因为每个表都需要它的别名,我需要将“as S”或其他东西放在某个地方,但我无法在这个查询中找到如何做到这一点。