简体   繁体   English

MySQL查询没什么

[英]MySQL query NOT something

This is the MySQL query I am running: 这是我正在运行的MySQL查询:

SELECT * 
    FROM wp_social_stuff_events 
    WHERE `user_1_id` = 63 
        OR `user_1_id` = 143 
        OR `user_2_id` = 63 
        OR `user_2_id` = 143 
    ORDER BY `event_timestamp` DESC LIMIT 100

How would I use that query but say I don't want any results where "user_1_id" is 53? 我将如何使用该查询,但会说“ user_1_id”为53时不希望有任何结果? I tried using AND user_1_id NOT 53 at the end but I can't seem to get that to work either (not sure if it is the correct way)? 我尝试在最后使用AND user_1_id NOT 53 ,但是我似乎也无法使它正常工作(不确定这是否正确)?

Any ideas? 有任何想法吗?

SELECT * 
FROM wp_social_stuff_events 
WHERE (`user_1_id` = 63 
OR `user_1_id` = 143 
OR `user_2_id` = 63 
OR `user_2_id` = 143)
AND user_1_id <> 53
ORDER BY `event_timestamp` DESC LIMIT 100

You can use != or <> for not equal as you can read in the MySql documentation . 您可以使用!=或<>表示不等于MySql文档中的内容 It's also require to have parentheses because AND is executed before OR. 它还需要带有括号,因为AND是在OR之前执行的。 See MySql Operator Precedent . 请参见MySql运算符先例

AND user_1_id <> 53

也会一样(不同于)。

You need: 你需要:

`user_1_id` <> 53

<> is the not equal operator in MySQL <>是MySQL中的不等于运算符

See here: 看这里:

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_not-equal http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_not-equal

SELECT * 
    FROM wp_social_stuff_events 
    WHERE `user_1_id` = 63 
        OR `user_1_id` = 143 
        OR ((`user_2_id` = 63 OR `user_2_id` = 143) 
         AND `user_1_id` <> 53) 
    ORDER BY `event_timestamp` DESC LIMIT 100

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM