我有以下查询,可从wpr_subscribers获取行,前提是查询中的条件。

SELECT subscribers.* FROM wpr_subscribers subscribers, wpr_followup_subscriptions subscriptions WHERE
            subscribers.id=subscriptions.sid AND
            subscribers.active=1 AND
            subscribers.confirmed=1 AND
            subscriptions.type='autoresponder' AND
            subscriptions.eid=$autoresponder_id AND
            subscriptions.sequence = -2 OR
            CEIL((subscriptions.last_date-subscriptions.doc)/86400) >= $message_index


查询返回每行两个。我该如何解决这个问题?

最佳答案

SELECT DISTINCT subscribers.* FROM wpr_subscribers subscribers, wpr_followup_subscriptions
subscriptions WHERE
        subscribers.id=subscriptions.sid AND
        subscribers.active=1 AND
        subscribers.confirmed=1 AND
        subscriptions.type='autoresponder' AND
        subscriptions.eid=$autoresponder_id AND
        subscriptions.sequence = -2 OR
        CEIL((subscriptions.last_date-subscriptions.doc)/86400) >= $message_index


DISTINCT关键字将帮助您仅返回表中的唯一(不同)行。您是否确定查询中AND和OR的逻辑,并且现在将收到的唯一数据确实是正确的。仅就信息而言,AND运算符的优先级高于OR,但是您可以使用括号将其优先。

关于php - 如何解决这个SQL查询?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6475375/

10-11 07:02