funeralcrasher: (Default)
funeralcrasher ([personal profile] funeralcrasher) wrote2006-09-19 10:15 pm
Entry tags:

[mysql] SELECT DISTINCT first letter of a varchar string

How could I SELECT DISTINCT the first letter of a string stored as a varchar? 

something like?

[identity profile] johnbutler.livejournal.com 2006-09-20 03:25 am (UTC)(link)
I gurgled this somewhere

SELECT id, COUNT(DISTINCT VARCHAR(RTRIM(LTRIM(elem)), 20)) FROM strings

maybe trim the length of the string minus 1?

In Python a string is an array, and you just ask for element 0. I'm guessing SQL does not make as much sense as Python.

I'm sure I'm wrong, but maybe you'll find something serendiculous.

Re: something like?

[identity profile] pkbarbiedoll.livejournal.com 2006-09-20 03:37 am (UTC)(link)
Found it -- thanks!!

MID(str,pos,len) is a synonym for SUBSTRING(str,pos,len).

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html