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' Quote Link to comment 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' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.