Link to home
Start Free TrialLog in
Avatar of the-miz
the-miz

asked on

php mysql search

I have written code to list all companies in our database alphabetically.  I have quick links at the top from A-Z and also have one other link that is suppose to get all companies that start with a number or special character.  Does anyone know the SELECT command in MySQL that can search all the companies and list them that begin with a number or special character.  Basically a list of all companies that DO NOT start with a letter.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of the-miz
the-miz

ASKER

Yes, I thought of those two ideas.  Using the OR statement in the clause will get long, for each letter in the alphabet.  Thought there might be a cleaner way
I think the cleaner way would be to alter the table.  That is what I would probably do.
Something like :

SELECT * FROM tableName WHERE NOT columnToCheck REGEXP '[A-Za-z0-9]';

Open in new window


That WHERE NOT REGEXP might need to be something like '[A-Za-z]{1}.*?' to find the companies like 3-M that start with numbers.  Not quite sure about that regex syntax in MySQL.  I still think I might change the table to add a selection column.  It would depend on the weight of the table scan that would result from the SELECT .. WHERE NOT.

Best to all, ~Ray