jmichael68 Posted August 19, 2010 Share Posted August 19, 2010 I have a problem when trying to query the table closed_mbl. I want to return the COUNT of all records that contain the locations below while excluding all these records that contain anything else besides AIR. How would I do this? Right now it returns the count of everything from all these locations. The field "method" is ignored. SELECT COUNT(*) FROM closed_mbl WHERE location = 'ALL' OR location = 'AUCKLAND' OR location = 'BRAZIL' OR location = 'DALIAN' OR location = 'EXPORT' OR location = 'GALWAY' OR location = 'ISUNICOV' OR location = 'KOLIN' OR location = 'SGALWAY' OR location = 'SHANNON' OR location = 'SOMI' OR location = 'SUZHOU' OR location = 'UNICOV' OR location = 'WUJIANG' OR location = 'WUJIANGCC' AND method = 'AIR' Link to comment https://forums.phpfreaks.com/topic/211185-conditional-statement-using-or-and-and/ Share on other sites More sharing options...
AbraCadaver Posted August 19, 2010 Share Posted August 19, 2010 Use parentheses: SELECT COUNT(*) FROM closed_mbl WHERE (location = 'ALL' OR location = 'AUCKLAND' OR location = 'BRAZIL' OR location = 'DALIAN' OR location = 'EXPORT' OR location = 'GALWAY' OR location = 'ISUNICOV' OR location = 'KOLIN' OR location = 'SGALWAY' OR location = 'SHANNON' OR location = 'SOMI' OR location = 'SUZHOU' OR location = 'UNICOV' OR location = 'WUJIANG' OR location = 'WUJIANGCC') AND method = 'AIR' Or use IN: SELECT COUNT(*) FROM closed_mbl WHERE location IN ('ALL','AUCKLAND','BRAZIL','DALIAN','EXPORT','GALWAY','ISUNICOV','KOLIN','SGALWAY','SHANNON','SOMI','SUZHOU','UNICOV','WUJIANG','WUJIANGCC') AND method = 'AIR' Link to comment https://forums.phpfreaks.com/topic/211185-conditional-statement-using-or-and-and/#findComment-1101264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.