MySQL查询列出从一个表到另一个表的字段值

时间:2018-06-29 10:00:11

标签: mysql subquery opencart

我有以下mysql查询:

  SELECT order_id, CONCAT(firstname, ' ', lastname) AS customer, shipping_code, total, currency_code, currency_value, date_added, date_modified FROM oc_order` o LEFT JOIN (select komercijalista from oc_customer (order.customer_id = customer.customer_id))

我试图在komercijalista表中列出oc_customer字段(属于oc_order表)中的值。我试图通过两者都具有的customer_id连接它们,但是我在左连接处失败。有什么建议吗?除了更好地学习mysql之外,我已经在尝试这样做,这是我需要您帮助的地方。谢谢。

2 个答案:

答案 0 :(得分:1)

SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified ,b.komercijalista FROM `oc_order` o left join (select komercijalista from oc_customer) b on o.order_id = b.customer.order_id

尝试

答案 1 :(得分:0)

感谢@ p.ganesh,我设法弄清楚如何编写查询。万一有人需要,这里是解决方案:

SELECT order_id, CONCAT(firstname, ' ', lastname) AS customer, shipping_code, total, currency_code, currency_value, date_added, date_modified FROM oc_order` o LEFT JOIN (select komercijalista from oc_customer (order.customer_id = customer.customer_id))