Ali
Ali

Reputation: 1058

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.

Upvotes: 0

Views: 174

Answers (6)

Nirav Ranpara
Nirav Ranpara

Reputation: 13785

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

Upvotes: 1

John Woo
John Woo

Reputation: 263733

try,

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

Upvotes: 1

MrCode
MrCode

Reputation: 64526

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

Upvotes: 1

StaticVariable
StaticVariable

Reputation: 5283

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

Upvotes: 1

Ancaron
Ancaron

Reputation: 504

Have you tried using : NOT ?

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

Upvotes: 1

AnandPhadke
AnandPhadke

Reputation: 13506

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

Upvotes: 1

Related Questions