tags:

views:

32

answers:

3

i mean i have songs table ok?? i want to make some things like that a | b | c | d click on a select from the database the songs that start by a Character how i can do that by the mysql???

+3  A: 

I believe you can use a LIKE statement to achieve this.

SELECT * FROM `table` WHERE `title` LIKE 'a%'

That will select anything where the title starts with an 'a', the % allows for anything after that. I'm not sure if this is case-sensitive or not (I don't believe it is), can someone confirm either way?

animuson
A: 

Here it is in Python because I can't be bothered to look up the crappy PHP syntax:

qry = "select song_name from songs where left(song_name, 1) = '%s'" % letter

This assumes that you haven't foolishly used a case sensitive collation as well. In case you were being silly and did that well:

qry = "select song_name from songs where left(lower(song_name), 1) = '%s'" %
      letter.lower()
Khorkrak
Right. Because string assignment in PHP is just **so** insane looking. Uh huh.
webbiedave
Really? All he even needs is the MySQL query line, I'm sure he can figure out how to use that in PHP.
animuson
Yep as you can see from the OP the bar to entry for PHP is rather low. And those stupid $ symbols everywhere are irksome.
Khorkrak
Quick suggestion about readability, SQL is less irksome to scan when you capitalize keywords/functions, i.e., `SELECT troll FROM comments WHERE username = 'you'`
webbiedave
Uppercase is for IBM mainframe programmers. It just looks like the code yelling at you and feels rather unnecessary - especially since there's a nice sql mode in Emacs that color codes your sql instead.
Khorkrak
Interesting. Thanks for *removing all doubt*.
webbiedave
+1  A: 

Retrieved from: http://www.webmasterworld.com/forum88/2320.htm

select * FROM `table` WHERE LEFT(`value`, 1) NOT BETWEEN 'A' AND 'Z'
Joseph