MySQL 找不到分配有别名的 table

MySQL cannot find table assigned with alias

我有一个问题...

select distinct(sod.sod_no), so.`so-no`, p.product_name, pod.prodstatus, po.`po-no`
                            from so_details sod
                            left join `sales-order` so on sod.so_number = so.`so-number`
                            left join products p on sod.product_id = p.product_id
                            left join po_details pod on sod.so_number = pod.so_number
                            left join `purchase-order` po on pod.po_number = po.`po-number` 
                            where so.status = 'In Progress'

但它出错了:

#1146 - Table 'po.po-no' doesn't exist

奇怪的是它可以毫无问题地读取sales-order table。可能是什么问题?

这一行有问题:

left join `sales-order` so on sod.so_number = so.`so-number`, po.`po-no`

我不知道为什么它有 po.po-no。同样在这一点上,您的查询仍然不知道别名 po.


我建议使用统一的样式来命名表和列。在 SQL 中通常是 snake_case,但您似乎在同一个数据库中使用 _-

这条线是什么?

left join `sales-order` so on sod.so_number = so.`so-number`, po.`po-no`

我认为您可以删除 , po.po-no 部分。看起来像是复制粘贴错误。