How do I select by a range of starting characters?

不问归期 提交于 2019-12-02 03:16:20

Try with Regex

WHERE symbolName REGEXP '^[A-F]'

Faster than Regular expressions and SUBSTRING() function calls. This will use the index of symbolName :

WHERE symbolName >= 'A' 
  AND symbolName < 'G'

There is an issue with the case sensitivity though. Do you want names which start with a..f too or not?

If you want only names that start with uppercase and the table has utf8 character set, use:

WHERE symbolName >= 'A' COLLATE utf8_bin
  AND symbolName < 'G' COLLATE utf8_bin

For other character sets, use the corresponding _bin collation.

SELECT *
FROM `eodList` 
WHERE datechanged>='$curdate' AND


((SUBSTRING(symbolName, 1, 1) >= "A" AND SUBSTRING(symbolName, 1, 1) <="F"))
GROUP BY symbolName 
ORDER BY dateChanged DESC
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!