简体   繁体   中英

Get result from sql with ignore some numbers

In MySQL table, i have a row for user groups. in this row i have user group numbers. i'm trying to get result from all usergroups except 0 and 5.

I tried with this code:

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

Problem is i don't know how i can ignore 0 and 5.

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

Have you tried using : NOT ?

Refer to http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html for further information.

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

If ug is a single number then you should be able to do

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

try,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM