Hello, I am creating a membership directory with an alphabetical index on top (similar to the address book in Yahoo Mail):
All A B C D E F (etc.)
I'd like to add links to only the letters that have records behind them, but right now I'm grabbing all of the records:
SELECT user_last_name
FROM users
ORDER BY user_last_name;
...and then cycling through them to fill an array:
$any_names_with_this_letter['a']
$any_names_with_this_letter['b']
etc.
...using a REGEXP('$letter%')
BUT if there are 10,000 members, it seems like a waste to grab all of the records when I'd rather just grab one record per letter.
Any suggestions for a tighter SQL statement, or another way of tackling this?
Thank you in advance!!
-Dale
PS. I'm trying to do this with only one SQL query.