Looking for something that does not CONTAIN a word. HOW?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Looking for something that does not CONTAIN a word. HOW?

Post by simonmlewis »

Code: Select all

SELECT id, title FROM products WHERE category != '%red%' ORDER BY title ASC
I am trying to run a query that checks the entire database table where a category name of a product does not have the word 'red' in it.

So if the category is called "red spot" or "blue and red stripe", it will not show it in the listing.

I thought it would be "DOES NOT CONTAIN" or something like that.

Anyone know?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Looking for something that does not CONTAIN a word. HOW?

Post by Eran »

[sql]SELECT id, title FROM products WHERE category NOT LIKE '%red%' ORDER BY title ASC[/sql]
http://dev.mysql.com/doc/refman/5.1/en/ ... tions.html
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Looking for something that does not CONTAIN a word. HOW?

Post by simonmlewis »

Crikey - I knew it would be simple, but brain didn't think of that!!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply