views:

48

answers:

2

Hi,

Is there a way for me to have two conditions on one field in MySQL Where?... I have a field called type and I want to do this:

WHERE `type` != 'name' AND `type` != 'photo'

I'm hoping for a better way to do that, so I could compare type to two possible options?

Thanks!

+7  A: 

if you mean AND - you probably do, because OR will always match :) -

WHERE `type` != 'name' AND `type` != 'photo'

then

WHERE `type` NOT IN ('name', 'photo')

should cut it.

Pekka
Thanks! Did the trick! :-)
tarnfeld
Please note that this is not always the best option. Using IN could make some queries on large tables very slow.
Lex
@Lex good point.
Pekka
+1  A: 

You can use

where type not in ('name','photo')
Sachin Shanbhag