Best way to select values that start with symbols

I have category ( title ) start with alphabetical A

$sql = "select * from category_data WHERE category LIKE 'A%'";

And is working, but how I can select from database the category ( title ) which don't start with [AZ] or [1-9] just with symbols


SELECT * FROM category_data WHERE ASCII(UPPER(LEFT(category,1))) IN(...)

You can pass allowed ASCII characters in your IN clause.

If you want to skip specific range, you can use NOT BETWEEN x AND y;


你可以简单地使用MySQL的REGEXP函数

SELECT * FROM `category_data` WHERE `category` REGEXP '^[^a-zA-Z0-9]'

您可以检查第一个字符是否不在字母表中或数字如下:

$sql = "select * from category_data WHERE substr(category,1) NOT LIKE '%[^a-zA-Z]%' AND substr(category,1) NOT LIKE '%[^0-9]%'";
链接地址: http://www.djcxy.com/p/29712.html

上一篇: 线程完成时是否释放一个锁?

下一篇: 选择以符号开头的值的最佳方法