user15063
user15063

Reputation:

How do you select rows from a mysql DB where a column begins with a number?

Beginning with a letter I know how to do:

WHERE mov_title REGEXP CONCAT('^(the )?', '$letter')

And this method will work if I substitute $letter with any number, so if its set to 1, it will find all records that begin with 1, but I need it to work for any number 0-9. How could I modify the query?

Upvotes: 1

Views: 181

Answers (3)

adam
adam

Reputation: 6738

Perhaps SQL Wild cards [charlist] might help:

http://w3schools.com/sql/sql_wildcards.asp

Upvotes: 1

LukeH
LukeH

Reputation: 269658

WHERE mov_title REGEXP '^(the )?[0-9]'

(Or set $letter to [0-9] if you want to keep using your existing WHERE clause.)

Upvotes: 3

kdmurray
kdmurray

Reputation: 3048

Another option may be to use the substring function

WHERE substring( post_title, 1, 1 ) between '0' and '9'

Upvotes: 3

Related Questions