mysql从何处加入选择

nbewdwxp  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(360)

我想从数据库中选择一行并加入该行。
当我使用此命令时,它工作正常:

SELECT p.* FROM pages AS p
JOIN products AS pro ON pro.page_id = p.id

但是当执行以下命令时,我得到了一个错误:

select p.* from pages as p where p.id = 21605
join products as pro on pro.page_id = p.id

为什么会这样?我怎样才能把结果传给第二个命令?

nc1teljy

nc1teljy1#

你的语法不正确

SELECT p.* FROM pages AS p
JOIN products AS pro 
ON pro.page_id = p.id
WHERE p.id = 21605

SELECT T.* 
FROM (SELECT p.* FROM pages AS p WHERE p.id = 21605) AS T
JOIN products AS pro 
ON pro.page_id = T.id

相关问题