如何解决这个sql查询?
我有以下查询来从 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
该查询返回每行中的两个。我该如何解决这个问题?
I have the following query to fetch rows from wpr_subscribers provided that the conditions in the query.
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
The query returns two of every row. How do I solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DISTINCT 关键字将帮助您仅返回表中唯一(不同)的行。您确定查询中 AND 和 OR 的逻辑以及您现在收到的唯一数据确实正确吗?仅供参考,AND 运算符优先于 OR,但您可以使用括号覆盖它。
DISTINCT keyword would help you in returning only the unique(distinct) rows in the table. Are you sure on the logic of AND and OR in the query and the unique data that you will now receive is indeed correct. Just for the info, AND operator has precedence over OR however you can override that by using parenthesis.
它可能是您的
OR
语句,无论
OR
的范围是什么,您都应该将其括在括号中It is probably your
OR
statementYou should enclose this in parenthesis for whatever the scope of the
OR
is