1

I want to run a mysql query to give me all available results that start with a number.

SELECT * FROM users WHERE username LIKE number + '%'

I tried using

LIKE REGEXP '^[0-9]

but it is not working for me

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jaylen
  • 39,043
  • 40
  • 128
  • 221

2 Answers2

3

You can use REGEXP:

SELECT * 
FROM users 
WHERE username REGEXP '^[0-9]'

SQL Fiddle Demo

sgeddes
  • 62,311
  • 6
  • 61
  • 83
2

Your RegExp is wrong, and the way you are using the REGEXP operator is wrong. Your code should be

WHERE username REGEXP '^[0-9].*'

SQLFiddle Example

Edit: I'm wrong about the RegEx portion. I didn't realize you don't need the .*

rbedger
  • 1,177
  • 9
  • 20
  • Thank you for your help but this return any string that contains a number. @sgeddes got it right :) Thanks – Jaylen Mar 19 '13 at 23:26