Jump to content

SELECT * FROM table WHERE problem


murfitUK

Recommended Posts

This should be so simple but my mind has gone blank and now I want to throw the computer out the window!I'm doing a "dictionary" which has two fields called "word" and "def".I want to do a list of words starting with letters A to E.This works:SELECT * FROM dict WHERE word LIKE 'A%' OR word LIKE 'B%' OR word LIKE 'C%' OR word LIKE 'D%' OR word LIKE 'E%';However, I am sure there is an easier way to do it, and I thought it was something like:SELECT * FROM dict WHERE word LIKE '[A-E]%';but it doesn't work. I've tried LIKE '{A-E}%' and '[AE]%' and every possible type of combination.Have I made this up? I'm sure I've seen it somewhere.Please help.

Link to comment
Share on other sites

What you are using is regular expressions in PERL, but that is what is used in PHP. The first example you show, like [A-E] should be like what you want in a PHP expression, but SQL doesn't work with PERL, at least not in the LIKE clause :)In SQL, the LIKE clause works with the sign % as a wildcard, and PERL uses a dot-asterisk for the same. That proves that LIKE doesn't uses PERL. What it does uses can be read here: http://www.mysql.org/doc/refman/5.0/en/str...-functions.htmlIt says it uses only % and _ for wildcards and no other syntax. It also refers to "REGEXP" which does uses regular expressions.Ha, skym had edited his post, he said it.

Edited by Dan The Prof
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...