user188962
user188962

Reputation:

How to find all records which are NOT in this array? (MySql)

I have an array which contains a bunch of ID:s...

I can't figure out how to write a query for finding all records which are NOT inside this array, in mysql.

    SELECT * FROM main_table WHERE ..........

Any ideas?

Thanks

Upvotes: 2

Views: 4373

Answers (2)

Sarfraz
Sarfraz

Reputation: 382686

Like this:

$str = implode(',', $your_array);

The above statements converts an array into comma-delimited string.

"SELECT * FROM main_table WHERE id NOT IN ('$str')"

More Info:

Upvotes: 11

Aillyn
Aillyn

Reputation: 23783

SELECT * 
  FROM main_table
 WHERE id NOT IN(1, 2, 3)

Upvotes: 6

Related Questions