0

Is there a performant way to query a large MySQL table for all entries that don't start with a letter?

I get the correct results using this, but it cannot take advantage of indexes:

SELECT * FROM `companies` WHERE `name` NOT REGEXP '^[a-z]+'

Edit: Anything better than the following?

SELECT * FROM `companies` WHERE `id` NOT IN (SELECT `id` FROM `companies` WHERE `name` RLIKE '^[a-z]');
  • 1
    [Is it possible to have function-based index in MySQL?](https://stackoverflow.com/q/10595037/1115360) may be of interest to you. – Andrew Morton Dec 01 '21 at 16:49
  • You may be able to split the "don't start with a letter" requirement into multiple range checks and use the index. It gets complicated if you have to deal with non-ASCII values. – Tim3880 Dec 02 '21 at 03:41

0 Answers0