我正在运行此SQL查询:
SELECT wp_woocommerce_order_items.order_id As No_Commande FROM wp_woocommerce_order_items LEFT JOIN ( SELECT meta_value As Prenom FROM wp_postmeta WHERE meta_key = '_shipping_first_name' ) AS a ON wp_woocommerce_order_items.order_id = a.post_id WHERE wp_woocommerce_order_items.order_id =2198
我得到这个错误:
#1054-‘on子句’中的未知列’a.post_id’。
我认为我的代码非常简单,但是我做错了。我究竟做错了什么?
您没有post_id在子查询中选择。您必须像下面这样在子查询中选择它:
post_id
SELECT wp_woocommerce_order_items.order_id As No_Commande FROM wp_woocommerce_order_items LEFT JOIN ( SELECT meta_value As Prenom, post_id -- <----- this FROM wp_postmeta WHERE meta_key = '_shipping_first_name' ) AS a ON wp_woocommerce_order_items.order_id = a.post_id WHERE wp_woocommerce_order_items.order_id =2198