[SOLVED] Condition with 'WHERE NOT'

Hello,

I’m looking for a way to solve following problem:

Making a SQL Query with "WHERE NOT" condition like this ->




SELECT * FROM partnerprograms_websites WHERE NOT ((website_id=1 AND partnerprogram_id=1) OR (website_id=1 AND partnerprogram_id=2))



I could not found a way to realize this with Yii Framework…

My ansatz was ->




$criteria = new CDbCriteria();

$criteria->condition="NOT ((website_id = 1 AND partnerprogram_id = 1) OR (website_id = 1 AND partnerprogram_id = 2)) ";


$models = PartnerprogramsWebsite::model()->findAll($criteria);



But it’s not working…

I can’t find a way to do this with Yii.

Thanks

Yii 1.1.4, MySQL

Hmm, what happens if you use ‘NOT…’ as condition?

But anyway, you could use some rules of basic boolean algebra to rewrite your condition.

EDIT:

Especially De Morgan’s law is helpful here:

http://en.wikipedia.org/wiki/De_Morgan’s_laws

:lol: I though too to De Morgan’s laws, but I thought that was too a workaround for write…


$criteria->condition="( (website_id <> 1 OR partnerprogram_id <> 1) AND (website_id <> 1 OR partnerprogram_id <> 2)) ";



I think that you can even factorize, but I am not sure:


$criteria->condition="( website_id <> 1 OR (partnerprogram_id <> 1 AND  partnerprogram_id <> 2)) ";

@Mike

Thanks -> De Morgan’s law was the solution

Reply to your question:

If I use "NOT" as condition it generates following query




SELECT * FROM partnerprograms_websites WHERE ( NOT ((website_id=1 AND partnerprogram_id=1) OR (website_id=1 AND partnerprogram_id=2)) )



And so it not works…

@zaccaria

Thank you for your answer too -> De Morgan’s law

Now it works ;)

By the way - how can i mark this thread as solved?

Edit your first post and add [SOLVED] to the topic.