Question: PHP 5.4 with MySQL  

Building off of this:

```
<?php
   $arr = ...
   $sql = 'SELECT COUNT(*) FROM table WHERE field IN ( ' . implode( ',', $arr ) . ' );';
   $result = $db->query( $sql );
?>

```

How would I display which items of the array ARE NOT in the table?

Answer: 
If your `$arr` variable is sanitized and safe to build a query with, you can use `union` operators to build a table containing all the words in the array, then you can left join that table to `table.field` and only keep array items where there was no match.

```
$arr = array('one','two');
$sql = "select item from (
      select '" . implode("' item union select '",$arr). "' item
    ) t1 left join table t2 on t2.field = t1.item
    where t2.field is null";

```

this will produce the following sql

```
select item from (select 'one' item union select 'two' item) t1 
    left join table t2 on t2.field = t1.item
    where t2.field is null

```
Just use "NOT IN", if your items is up to 10 elements:

```
<?php
   $arr = array('one','two');
   $filterExisting = "'" . implode("', '", $arr ) . "'";
   $sql = "SELECT COUNT(*) FROM table WHERE field NOT IN (". $filterExisting .")";
   $result = $db->query($sql);
?>

```