我正在尝试使用以下MySQL查询从order_product表中检索产品名称:
查询
SELECT o.order_id,
CONCAT(o.firstname, ' ', o.lastname) AS customer,
( SELECT os.name
FROM order_status os
WHERE os.order_status_id = o.order_status_id
AND os.language_id = '" . (int)$this->config->get('config_language_id') . "'
) AS order_status,
( SELECT name
FROM order_product
WHERE order_id = o.order_id
LIMIT 1
) AS product_name,
o.shipping_code,
o.total,
o.currency_code,
o.currency_value,
o.date_added,
o.date_modified,
o.telephone,
o.shipping_city,
o.order_type,
o.shipping_address_1
FROM order o
AND product_name LIKE '%smart tv3%'`
请帮我解决此错误。并且还给我一个指导。
答案 0 :(得分:0)
我通过在查询中替换AND到HAVING解决了错误。 :)
<强> QUERY 强>
SELECT
o.order_id,
CONCAT(o.firstname, ' ', o.lastname) AS customer,
(
SELECT
os.name
FROM
order_status os
WHERE
os.order_status_id = o.order_status_id
AND os.language_id = '" . (int)$this->config->get('config_language_id') . "'
)
AS order_status,
(
SELECT
name
FROM
order_product
WHERE
order_id = o.order_id LIMIT 1
)
AS product_name,
o.shipping_code,
o.total,
o.currency_code,
o.currency_value,
o.date_added,
o.date_modified,
o.telephone,
o.shipping_city,
o.order_type,
o.shipping_address_1
FROM
order o
HAVING
product_name LIKE '%smart tv3%'`
感谢@wayneOS和其他人回答我的问题:)