I need to write a query to select members whose username starts with Letters "A" through "J"
asasfaf... basdsdfsdfgs ... jsdserwer
How do I do that?
11.4.2. Regular Expressions
I was hoping it would be something like:
WHERE username LIKE ('a% OR 'b% OR 'c% OR 'd% OR 'e% OR 'f% OR 'g% OR 'h% OR 'i% OR 'j%)
that is an option, synatax is:
WHERE username LIKE 'a%' OR LIKE 'b%' OR LIKE 'c%' ...
regexp would be a shorter query, but i have no ida which would be faster
Great.
I keep getting error on this...
dagon;10913445 wrote:that is an option, synatax is: WHERE username LIKE 'a%' OR LIKE 'b%' OR LIKE 'c%'
WHERE username LIKE 'a%' OR LIKE 'b%' OR LIKE 'c%'
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE 'a%' OR LIKE 'b%'
where username like 'a%' or username like 'b%' or username like 'c%' or ....
perfect. Works.
thanks for the correction weedy, I have been writing mysql queries for the last 6 hours and i still manage to screw up the syntax.
You'd think there'd be a substring function that one could use that and see if the first letter was IN ('a','b','c').... If I had an urge to find out I'd look in whatever manual was appropriate.
Weedpacket;10913486 wrote:You'd think there'd be a substring function that one could use that and see if the first letter was IN ('a','b','c').... If I had an urge to find out I'd look in whatever manual was appropriate.
there is
SELECT * FROM foo WHERE bar REGEXP 'a|b|c|d|e|f|g|h|i|j'
And even shorter:
SELECT foo FROM bar WHERE foo REGEXP '^[a-j]';