从sql获取结果忽略一些数字

时间:2012-10-10 08:18:34

标签: php mysql

在MySQL表中,我有一行用户组。在这一行我有用户组号码。 我正在尝试从除0和5之外的所有用户组获得结果。

我尝试使用此代码:

$sql = $db->query("
SELECT 
author FROM dle_photo_post where ug<'5' and moder ='0'
");

问题是我不知道如何忽略0和5。

6 个答案:

答案 0 :(得分:1)

SELECT 
author FROM dle_photo_post where ug not in('5','0') and moder ='0'

答案 1 :(得分:1)

你试过用过:不是吗?

有关详细信息,请参阅http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

答案 2 :(得分:1)

SELECT author FROM dle_photo_post where ug!=5 and ug!=0

答案 3 :(得分:1)

如果ug是单个号码,那么您应该可以

SELECT
    author
FROM
    dle_photo_post
WHERE
    ug <> 5 AND ug <> 0

答案 4 :(得分:1)

试,

SELECT author 
FROM dle_photo_post 
where usergroups NOT IN (0, 5)

答案 5 :(得分:1)

$sql = $db->query("
SELECT 
author FROM dle_photo_post where ug not in('0','5')
");