Mysql select where not euqal to array values

purpleoak used Ask the Experts™
i need to do a select where a particular field is not equal to any of the values in the array. so for instance my array has


mysql_query("SELECT partnumber FROM table WHERE ordernumber != arrayvalues")

The issue is the amount in the values can change and potentially be 20/30 values.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Use implode() to convert the array into a CSV list, and use the SQL IN clause to compare against a list of values:
$a_test = array(1,2,3,4,5);
$v_test_list = implode(",", $a_test);
..mysql_query("SELECT partnumber FROM table WHERE ordernumber not in($v_test_list)");

Open in new window


I need to go disable your internet connection so I can get a chance to answer the questions. :)
:)  Gotta try and catch you guys up eh?
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Haroon Ur RashidSr. Software Engineer

hi, another way is
 WHERE not fieldname IN (ListOfValues)

WHERE * from Table Where FieldName Not IN (ListOfValues)


Thank you very much. Exactly what i needed. Sorry i didn't reply sooner. I thought i would post and leave over night. Guess i didn't need to wait all that long.
Glad to help.. thanks for the points..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial