Mysql select where not euqal to array values

purpleoak
purpleoak used Ask the Experts™
on
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

133007
133005
133090

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.
Comment
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

Commented:
@TheFoot

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

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


WHERE * from Table Where FieldName Not IN (ListOfValues)

Author

Commented:
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