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 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. 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 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 } 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 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? 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' 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. Link to comment https://forums.phpfreaks.com/topic/229384-using-in-query/#findComment-1181912 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.