Hello forums
is ti possible to query a mysql db and exclude everything that is in an array something like :
$myarray = array[3,12,4,5,6,112];
$query =“SELECT id FROM table WHERE id != $myarray”;
I know I can do it like this :
$query = “SELECT id FROM table WHERE id != 3 AND id != 12”; etc etc but the thing is the array is generated dynamically
Any ideas? Thanks
hash
January 23, 2010, 5:39am
2
SELECT something FROM table WHERE field NOT IN (1,2,3)
OMG there is such thing as NOT IN in mysql jeez I didn’t know that I have a lot to learn, let me try that and see if it works …Thanks hash
One thing to note stonedeft don’t use != for NOT in queries as != is MySQL specific syntax, instead use <> as that will enable the code to port better to other servers which might not necessarily have MySQL installed.
It works I just need to join my arrat first with a ,
thanks SpacePhoenix thats a good advice however when you say <> do you mean greater than or less than or there is something else between the lines ???
hash
January 23, 2010, 7:58am
6
I’m not sure about the mysql internals, but that can safely be read as “not equal”, that’s how it’s written in the manual.