Welcome to WebmasterWorld Guest from 54.221.9.209

Forum Moderators: open

Message Too Old, No Replies

MySQL LIKE condition

     
12:38 am on Jun 11, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 15, 2006
posts:140
votes: 0


hey i have a question is it possible to combin the LIKE feature of mysql to construct a query that would be like this.

select * from table WHERE field LIKE 'chris' AND NOT LIKE 'chriostopher'

if you can could someone please tell me how?

3:18 am on June 11, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 6, 2004
posts:53
votes: 0


You can combine LIKE in queries

select * from table WHERE field LIKE 'chris%' AND field NOT LIKE 'christopher%'

The above query will return every name beginning 'chris' but will not return names beginning 'christopher'

(I assumed you made a typo in your example with 'chriostopher')

1:15 pm on June 12, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 15, 2006
posts:140
votes: 0


yes i did make a typo, thats great, so you could i use this with numbers for example if a number field contains the number 1555 and 1556 if i exclude the 1556 will i get all of the records with 1555 in the field?
4:08 pm on June 12, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 6, 2005
posts:575
votes: 0


Yes