views:

143

answers:

2

In my view I have an alphabet based selector, to select manufacturers by the first letter of their name. I got that part working. But I have manufacturers whose name starts with a number, for example 3M, or 3DLabs. In the view I have the character "#" to group all those. What should my query/find method look like to retrieve all names that don't start with an alphabet letter.

+2  A: 

You probably want to use a Regular Expression.

What language are you using?

Here is the SQL2005 version:

select *
from myTable
where myField like '[^a-z]%'
Mitchell Gilman
I'm using RubyOnRails+mysql. Actually, what I am looking for is the negation of what you wrote; when the number sign is selected, I want to show all names that don't start with the alphabet letters, that is I want to show all names that start with a number.
On SQL2005 that show the names that do NOT start with a letter. (The ^ makes the regex negative). You could also do like '[0-9]%' to only show numbers (and no special characters). Sorry, I don't know enough about mysql to know if my code also works there. :-(
Mitchell Gilman
+1  A: 

I think I got it

SELECT * FROM manufacturers WHERE ( name REGEXP '^[0-9]') ORDER BY name

Was just posting something similar: http://dev.mysql.com/doc/refman/5.1/en/regexp.html
hometoast
This gets only digits, not all non-alphabetics.
joel.neely