I have a list of values in my PHP code. We could say:
$myList = array("one", "two", "three")
I'd like to select the values of the array that not exists in a table.
I've tried something similar to this:
SELECT *
FROM (my-list-here)
WHERE
NOT EXISTS (
SELECT * FROM my_table WHERE value IN (my-list-here)
)
I don't know how to select values from that array :(
I don't know if we can really execute a SQL query for an array and not a table like you've done
SELECT *
FROM (my-list-here)
WHERE...
What you can do is get the array of the values from the table using query and use array_diff
to remove the values that exists in the $myList
array.
I think you have to do this pragmatically:
Your array:
$myList = array("one", "two", "three");
Get data from table (PDO library for example)
$dbh = new PDO("mysql:host=".$host.";dbname=".$dbName, $username, $password);
$sth = $dbh->prepare("SELECT * FROM my_table");
$sth->execute();
/* Fetch all of the values of the first column for example */
$tableList = $sth->fetchAll(PDO::FETCH_COLUMN, 0);
Exclude $tableList from $myList
$results = array_diff($myList, $tableList);