funeralcrasher (
funeralcrasher
) wrote
2006
-
09
-
19
10:15 pm
Current Music:
Ultravox - Mr. X
Entry tags:
mysql
,
php
[mysql] SELECT DISTINCT first letter of a varchar string
How could I SELECT DISTINCT the first letter of a string stored as a varchar?
Flat
|
Top-Level Comments Only
something like?
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?
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
2 comments
Post a new comment
Flat
|
Top-Level Comments Only
[
Home
|
Post Entry
|
Log in
|
Search
|
Browse Options
|
Site Map
]
something like?
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?
MID(str,pos,len) is a synonym for SUBSTRING(str,pos,len).
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html