a query issue

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

a query issue

Post by itsmani1 »

my table has 2 columns id and name
i want to select all those names that start with a number [0-9] using a query is this possible?

for example for selecting all the names starting with A i am doing this:

Code: Select all

name LIKE 'A%'
I need help to select name starting with number like "100 5 The Zones Acoustic Xmas" etc

thank you
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You can use regular expressions.

Code: Select all

SELECT foo FROM tbl_name WHERE name REGEXP '^[0-9]'
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

Code: Select all

SELECT * 
FROM mk
WHERE EventName LIKE REGEXP '^[0-9]%'
LIMIT 0 , 30
Error:
MySQL said:

#1064 - 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 'REGEXP '^[0-9]%'
LIMIT 0, 30' at line 1
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's no LIKE when working with REGEXP.
Post Reply