MySQL在哪里NOT IN名称数组?

时间:2012-09-01 18:35:36

标签: php mysql sql

我想排除这些名称为

的专辑
$ban_album_names = array('Wall', 'Profile', 'Cover', 'Instagram');

我如何正确写作,

SELECT * FROM albums WHERE name NOT IN ???

如何让它在数组中查看,如果名称匹配则应该!=行

2 个答案:

答案 0 :(得分:67)

试试这个:

$sql = "SELECT *
    FROM albums
    WHERE name NOT IN ( '" . implode( "', '" , $ban_album_names ) . "' )";

答案 1 :(得分:25)

MySQL代码是

SELECT * FROM albums WHERE name NOT IN ('Wall', 'Profile', 'Cover', 'Instagram')