Page 1 of 1
help needed with "like" on sql syntax
Posted: Mon May 17, 2004 9:03 am
by pelegk2
i want to make a select with a like
where i want the start of the string to be in the range of
01..09
means :
01dfgasfasdf321
02df465as4dfwer
and so on to...
09sd1231asdf
how do i do that?
thnaks in advance
peleg
Posted: Mon May 17, 2004 9:50 am
by pickle
Hmm, I'd look into regular expressions for this. Or, you could do multiple "OR" statements in the WHERE clause (WHERE string = '01%' OR string = '02%' and so on).
Posted: Mon May 17, 2004 9:52 am
by leenoble_uk
You may have to use a REGEXP instead of LIKE.
To use a LIKE you'd have to do:
LIKE '01%' OR
LIKE '02%' OR
LIKE '03%' etc etc.
I haven't ever had to use REGEXP in an sql query so someone else may have to help with the exact syntax but it's probably something like
WHERE col_name REGEXP('^0[1-9][:alnum:]+$')
Check it out in the mysql manual.
Posted: Mon May 17, 2004 9:57 am
by leenoble_uk
I just looked it up. You don't need the brackets because it's not a function:
WHERE col_name REGEXP "^0[1-9][:alnum:]+$"
should do the trick.