挂mysql查询

时间:2013-03-04 18:05:51

标签: mysql sql join

我遇到以下查询的问题

select
ord.order_id, 
ordProduct.product_id,
coupProd.product_id,
coup.date_end as DateEnd, coup.coupon_id
from `order` ord
inner join order_product ordProduct on ord.order_id = ordProduct.order_id
inner join coupon_product coupProd on ordProduct.product_id = coupProd.product_id
inner join coupon coup on coupProd.coupon_id = coup.coupon_id
where (coup.date_end > curdate());

如果我删除where子句,查询执行正常,否则它只是挂起。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

它本身不是解决方案,但作为一种解决方法,您可以将其作为嵌套查询完成。即,

SELECT * FROM (
    SELECT
    ord.order_id, 
    ordProduct.product_id,
    coupProd.product_id,
    coup.date_end AS DateEnd, coup.coupon_id
    FROM `order` ord
    INNER JOIN order_product ordProduct ON ord.order_id = ordProduct.order_id
    INNER JOIN coupon_product coupProd ON ordProduct.product_id = coupProd.product_id
    INNER JOIN coupon coup ON coupProd.coupon_id = coup.coupon_id)
WHERE (DateEnd > CURDATE());