Jump to content

select where first character of field is not a letter


scarhand

Recommended Posts

lets say i have a table with the following in the "colors" field:

 

3 reds

red

orange

4  blues

$%$ blues

 

i need a query that will select the 3 rows where the first character of "colors" is not an actual letter, so the results returned should be:

 

3 reds

4  blues

$%$ blues

 

i have no idea how to do this. i wrote a query that selects by the first character if it is a letter.....but im stumped with this.

I believe this will work. If it isn't right, I'm sure someone will point it out, but give it a try.

 

SELECT `field` FROM `table` WHERE `field` NOT REGEXP '[:alpha:]'

heres a better of what i'm trying to do using your example pikachu

 

"select colors, count(*) as count from `table` where substring(`colors`, 1, 1) NOT REGEXP '[:alpha:]' group by `colors` order by `colors` asc";

 

though this is not working, you can see what im trying to do

ok so this works:

 

"select * from `colors` where `color` REGEXP '^[^[:alpha:]]'";

 

however i need to group them and do a count, and this doesn't work:

 

select color, color_slug, count(*) as count from `colors` where `color` REGEXP '^[^[:alpha:]]' group by `color` order by `color` asc

 

all it does is seem to group all of the rows together if they match the REGEXP.

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.