whats the query to select a distict record that starts with a certain letter... before i would do it like this, i would have a column in my table that says starting letter and for each thing i insert into the database i would have a form feild and ask for its starting letter
then i would have a list of letters like A, B, C, D, E, F, G, H, I... so on
each one would be linked... say A would be linked to page.php?letter=A
that way i could select everything where the starting letter = the $letter
and the $letter variable would be equal to $_GET['letter']
i realize there is prolly a distinct query that could do the same thing..
sql to select distinct records that start with the letter A
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: sql to select distinct records that start with the letter A
Perhaps something like..
.. untested.
Code: Select all
SELECT DISTINCT `word`
FROM `dictionary`
WHERE SUBSTRING(`word`, 1) = 'A'Re: sql to select distinct records that start with the letter A
Use[sql]... WHERE `word` >= 'A' AND `word` < 'B'[/sql]
This way MySQL may use indexes.
This way MySQL may use indexes.
There are 10 types of people in this world, those who understand binary and those who don't
Re: sql to select distinct records that start with the letter A
This would also work:
[sql]... WHERE `word` LIKE 'A%'[/sql]
[sql]... WHERE `word` LIKE 'A%'[/sql]