jakebur01 Posted March 2, 2011 Share Posted March 2, 2011 What is the correct way to do this? SELECT DISTINCT CLASS FROM ARINVT01 WHERE (`CLASS` <> `AD ALLOWANCE`, `CLASS` <> 'STOP CHARGE', `CLASS` <> 'MISCELLANEOUS') ORDER BY CLASS ASC Quote Link to comment https://forums.phpfreaks.com/topic/229384-using-in-query/ Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2011 Share Posted March 2, 2011 The commas in the WHERE clause should be ANDs and/or ORs. Quote Link to comment https://forums.phpfreaks.com/topic/229384-using-in-query/#findComment-1181886 Share on other sites More sharing options...
jakebur01 Posted March 2, 2011 Author Share Posted March 2, 2011 I tried it with AND and OR and I get this error for both: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource   SELECT DISTINCT CLASS FROM ARINVT01 WHERE `CLASS` <> `AD ALLOWANCE` AND `CLASS` <> 'STOP CHARGE' AND `CLASS` <> 'MISCELLANEOUS' ORDER BY CLASS ASC    Quote Link to comment https://forums.phpfreaks.com/topic/229384-using-in-query/#findComment-1181898 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2011 Share Posted March 2, 2011 Then you need to echo the query, along with mysql_error() if the query fails. $query = "SELECT whatever FROM table"; if( !$result = mysql_query($query) ) { Â Â echo "<br>Query: $query<br>Failed with error: " . mysql_error() . '<br>'; } else { Â Â // continue with processing the query result } Quote Link to comment https://forums.phpfreaks.com/topic/229384-using-in-query/#findComment-1181902 Share on other sites More sharing options...
jakebur01 Posted March 2, 2011 Author Share Posted March 2, 2011 SELECT DISTINCT CLASS FROM ARINVT01 WHERE `CLASS` <> `AD ALLOWANCE` AND `CLASS` <> 'STOP CHARGE' AND `CLASS` <> 'MISCELLANEOUS' ORDER BY CLASS ASC Quote Link to comment https://forums.phpfreaks.com/topic/229384-using-in-query/#findComment-1181908 Share on other sites More sharing options...
Pikachu2000 Posted March 2, 2011 Share Posted March 2, 2011 What was the error that was returned? Quote Link to comment https://forums.phpfreaks.com/topic/229384-using-in-query/#findComment-1181909 Share on other sites More sharing options...
jakebur01 Posted March 2, 2011 Author Share Posted March 2, 2011 Failed with error: Unknown column 'AD ALLOWANCE' in 'where clause' Quote Link to comment https://forums.phpfreaks.com/topic/229384-using-in-query/#findComment-1181910 Share on other sites More sharing options...
jakebur01 Posted March 2, 2011 Author Share Posted March 2, 2011 It was the quotations. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/229384-using-in-query/#findComment-1181912 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.