PDA

View Full Version : Search [alphabetically, first letter] a | b | c | d | e.. ?


Harlequin
01-21-2004, 03:18 PM
I'm new to the SQL searching thing and I've been trying to figure out a way to allow a user search via the first letter on a certain table, such as "title" or "topic" or something.


So by a user clicking a or b or c or d.. so on and so forth..

The result would bring back and alphabetical order of topics with -just- that letter (such as the example below).

If user clicks A, result is:

alien
alligator
ant
art
asp

If user clicks B, result is:

beast
bite
brake
butter

..

I'm assuming to get the function to go alphabetical, it'd be GROUP BY or ORDER BY with an ASC or DESC, but the searching via a first letter is kind of killing me. ;)

NTLDR
01-21-2004, 03:38 PM
WHERE like 'a%'

That would get all entries where the title column starts with an 'a'.

Xenon
01-21-2004, 03:55 PM
if you want to ignore cases it's

WHERE UCASE(fieldname) LIKE 'A%'

NTLDR
01-21-2004, 03:57 PM
It normally seems to ignore the case anyway, at least on 4.0.15, I just tried and got A and a returned. Although normally I'd put a case check in to be sure ;)

Harlequin
01-21-2004, 04:34 PM
Wow. Thanks for the speedy replies. :)

I'll definitely give it a shot.

Thankies thankies!

Xenon
01-21-2004, 04:38 PM
It normally seems to ignore the case anyway, at least on 4.0.15, I just tried and got A and a returned. Although normally I'd put a case check in to be sure ;)
hmm, it didn't ignore cases when i checked it lasttime, and i know other DB's like DB2 don't ignore it.

bah, maybe it's just a setting, which is changeable ;)