How do I select by a range of starting characters?

后端 未结 3 1927
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 00:24

Here is my mySQL query:

SELECT *
FROM `eodList` 
WHERE datechanged>=\'$curdate\' 
GROUP BY symbolName 
ORDER BY dateChanged DESC

How do I ge

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-23 01:09

    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.

提交回复
热议问题