jandrews3 Posted August 17, 2008 Share Posted August 17, 2008 I'm having trouble with the following query: $query = "SELECT * FROM chs_students WHERE spanish = 0 and registerm = '' or spanish = 0 and registerf = '' ORDER BY lname, fname"; I modified it from the following query (which is functional): $query = "SELECT * FROM chs_students WHERE spanish = 0 ORDER BY lname, fname"; Is the first query valid, or can I not use AND and OR in this manner? I'm trying to select only those entries whose spanish variable is zero and either whose registerf or registerm varibales are empty. Thanks. Link to comment https://forums.phpfreaks.com/topic/120069-query/ Share on other sites More sharing options...
Barand Posted August 17, 2008 Share Posted August 17, 2008 use (..)s WHERE (spanish = 0 and registerm = '') or (spanish = 0 and registerf = '') Link to comment https://forums.phpfreaks.com/topic/120069-query/#findComment-618522 Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 And use boolean logic: WHERE spanish = 0 and (registerm = '' or registerf = '') Also it is possible, that empty registerm and registerf values are null. In such case use: WHERE spanish = 0 and (registerm IS NULL or registerf IS NULL) Link to comment https://forums.phpfreaks.com/topic/120069-query/#findComment-618524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.