help needed with "like" on sql syntax

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
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

help needed with "like" on sql syntax

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
leenoble_uk
Forum Contributor
Posts: 108
Joined: Fri May 03, 2002 10:33 am
Location: Cheshire
Contact:

Post 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.
leenoble_uk
Forum Contributor
Posts: 108
Joined: Fri May 03, 2002 10:33 am
Location: Cheshire
Contact:

Post 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.
Post Reply