SELECT WHERE field DOES NOT CONTAIN a string??? HOW?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

SELECT WHERE field DOES NOT CONTAIN a string??? HOW?

Post by superwormy »

I want to select only records where a field DOES NOT contain a string in it...

So for instance, the contents of the fields might be:

Record 1: 1, bla bla bla i rock http://www bla bla bla
Record 2: 2, wowzers that rocks bla balj
Record 3: 3, this rocks mysql is great http://www.blue


Now, I want to select all records where that field DOES NOT have http:// in it. So it should JUST SELECT RECORD 2.

Whats the syntax for that?
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

You should be able to use "not like" to do this:

Code: Select all

select * from table
where field NOT LIKE '%http://%' ;
You can also do it with a regular expression using REGEX. See the MySQL docs at http://www.mysql.com/doc/en/String_comp ... tions.html
Post Reply