MySQL select 子句中的子查询
MySQL subquery in select clause
SELECT op.*,
(op.total + op.total * 0.21) as price,
(SELECT p.`image` FROM oc_product` p WHERE op.product_id = p.product_id LIMIT 1) AS image
FROM `oc_order_product` op WHERE op.order_id = '80'
我找不到它返回的查询有什么问题。
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use
near 'oc_order_productop WHERE op.order_id = '80'
LIMIT 0, 25' at
line 3
在 oc_product
之前添加一个反引号,所以
SELECT p.`image` FROM oc_product`
应该看起来像
SELECT p.`image` FROM `oc_product`
SELECT op.*,
(op.total + op.total * 0.21) as price,
(SELECT p.`image` FROM oc_product` p WHERE op.product_id = p.product_id LIMIT 1) AS image
FROM `oc_order_product` op WHERE op.order_id = '80'
我找不到它返回的查询有什么问题。
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'oc_order_product
op WHERE op.order_id = '80'
LIMIT 0, 25' at line 3
在 oc_product
之前添加一个反引号,所以
SELECT p.`image` FROM oc_product`
应该看起来像
SELECT p.`image` FROM `oc_product`