简体   繁体   中英

An Issue with my MySql Syntax (I Think)

This is the first time I've had to post on stack overflow so I Hope you can all help!

What I'm trying to do is Pull all the information from a database that doesn't meet a specific criteria. In this case basically I want all the information that doesn't equal status 5, 4 and 3 The SQL code I have doesn't seem to stop that. Ill Post it below :)

$query = $db->query("
SELECT * 
  FROM `job_apps_responses` 
 WHERE status != 5 
    OR status != 4 
    OR status != 3
" );

Whats happening is that Status 3 is still displaying with the rest and It shouldn't be. (according to how I've written the code, Clearly its wrong)

Thanks :D

You shouldn't use OR but you should use AND

As an alternative may I suggest to use NOT IN like this:

$query = $db->query( "SELECT * FROM `job_apps_responses` WHERE status NOT IN (5,4,3)" );

使用NOT IN

SELECT * FROM `job_apps_responses` WHERE status NOT IN (5,4,3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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