NameSilo

SQL Order By

NamecheapNamecheap
Watch

dc1pop

VIP Member
Impact
13
Im trying to list items on a page by letter, But i need to know what statement to use so it only selects words beginging with the spcificed letter. For example i will have a page with a heading of that letter and then the results:

Heading A

A Results


Only help would be great!

Thanks.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Code:
SELECT * FROM table ORDER BY name LIKE 'a%';
This will return only results where name begins with a.
 
0
•••
order by would alphabetize a column either ascending or descending. If you want to pick all records in a DB where a field begins with "A", then your SQL would look like this:

PHP:
SELECT * FROM <TABLE> WHERE <FIELD> LIKE 'A%' order by <FIELD> ASC

If you want them in reverse alphabetical order (e.g Z to A), it would look like this:

PHP:
SELECT * FROM <TABLE> WHERE <FIELD> LIKE 'A%' order by <FIELD> DESC

Of course, if you have both capital and lower case A's in the DB, you might need to do something like this:

PHP:
SELECT * FROM <TABLE> WHERE <FIELD> LIKE 'A%' or <FIELD> like 'a%' order by <FIELD> ASC

Cheers!

-Bob
 
0
•••
Thanks works well :)
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back