以下子查询返回多于1行
SELECT date,
order_no,
(SELECT product_name
FROM product
WHERE product_id IN (SELECT product_id
FROM order_det)),
qty
FROM order_det
WHERE order_no IN (SELECT order_no
FROM order_id
WHERE cust_id = (SELECT log_id
FROM orderpanel_log
ORDER BY orderpanel_log.date DESC
LIMIT 1))
如何预防?
答案 0 :(得分:0)
您的子查询
(SELECT product_name
FROM product
WHERE product_id IN (SELECT product_id
FROM order_det ))
返回的行可能更多,因此您应减少重新调整的行数,例如:
(SELECT product_name
FROM product
WHERE product_id = (SELECT product_id
FROM order_det
limit 1 ))
。
SELECT date,
order_no,
(SELECT product_name
FROM product
WHERE product_id = (SELECT product_id
FROM order_det
limit 1 ))
qty
FROM order_det
WHERE order_no IN (SELECT order_no
FROM order_id
WHERE cust_id = (SELECT log_id
FROM orderpanel_log
ORDER BY orderpanel_log.date DESC
LIMIT 1))
但是我建议您尝试使用内部联接重构查询,并减少或避免使用子查询
SELECT od.date,
od.order_no,
p.product_name,
od.qty
FROM order_det od
INNER JOIN product p on p.product_id = od.product_id
INNER JOIN order_id oi on o1.order_no = od.order_no
WHERE cust_id = (
SELECT log_id
FROM orderpanel_log
ORDER BY orderpanel_log.date DESC
LIMIT 1
)