Perl Programming Page 2 - SELECT Queries and Perl |
The last bit of SQL that we will look at will be how to order the output. TheORDER BYclause allows us to specify on which field the output should be sorted. Let’s say we want to show all the musician information, but the output is to be sorted by name. mysql> SELECT * FROM musicians ORDER BY name; player_id name phone 2 Geddy Lee 555-2323 5 Lenny Kravitz 555-5656 3 Marshall Mathers III 555-3434 6 Mike Diamond 555-6767 1 Roger Waters 555-1212 4 Thom Yorke 555-4545 6 rows in set (0.00 sec) How about all the instruments and their difficulty from easiest to hardest. mysql> SELECT instrument, difficulty FROM instruments ORDER BY difficulty; Let’s list all the percussion instruments sorted on the name: mysql> SELECT instrument FROM instruments You may be wondering, “Can I reverse that order?” Yup, using the qualifierDESC . mysql> SELECT instrument FROM instruments +------------+
blog comments powered by Disqus | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||