2017-08-10 79 views
-1

我有一個查詢分配表...MySQL不能找到別名

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表沒有任何問題。可能是什麼問題?

+1

第一次加入你爲什麼使用PO表? 'left join'sales-order' so so sod.so_number = so.'so-number',po.'po-no'' – Riad

+0

請注意,DISTINCT不是函數。而列標識符中包含' - '則是魯莽的。 – Strawberry

回答

2

這條線是什麼?

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

我認爲你可以刪除, po.po-no部分。它看起來像複製粘貼錯誤。

0

問題是這一行:

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

我不知道爲什麼它有po.po-no。此時,您的查詢仍然不知道別名po


我建議使用統一風格命名錶和列。在SQL中,它通常是snake_case,但它似乎是在同一數據庫中使用_-