Click to See Complete Forum and Search --> : MySQL wildcards support?


webdev077
11-03-2008, 01:30 AM
hello everyone:
i am wondering if Mysql supports
range operator and negation character in wildcards.

In my talbe i have a column called lastname:
records in lastname are: hansen, svendson, petterson and peter.

1. I wrote a query try to find out last name start with letter 'h', 's' or 'p'
followed by any characters.


select * from person
where lastname like '[hsp]%';


the result retured an empty set. Seems to me Mysql doesn't support range
operator []

2.
select * from person
where firstname like '[^t]%';


I want to find out that entry that doesn't start with letter 't'
the result also returned a empty set.

Please give me some advises on how to make wildcards works in these 2 cases.

scragar
11-03-2008, 02:16 AM
MySQL doesn't have range operators like that, see the LIKE (http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like) reference guide.

You have only really 1 solution:
SELECT * FROM `person`
WHERE
`lastname` LIKE 'h%' OR
`lastname` LIKE 's%' OR
`lastname` LIKE 'p%';
SELECT * FROM `person`
WHERE `firstname` NOT LIKE 't%';