Perl
  Home arrow Perl arrow Page 2 - SELECT Queries and Perl
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

SELECT Queries and Perl
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 3
    2008-03-27

    Table of Contents:
  • SELECT Queries and Perl
  • The ORDER BY Clause
  • More Complicated SELECTs
  • Introduction to DBI

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    SELECT Queries and Perl - The ORDER BY Clause
    (Page 2 of 4 )

    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;
    +------------+------------+
    | instrument | difficulty |
    +------------+------------+
    | drums      |          0 |
    | conductor  |          0 |
    | keyboards  |          1 |
    | bass       |          3 |
    | timpani    |          4 |
    | guitar     |          4 |
    | trumpet    |          5 |
    | piccolo    |          5 |
    | vocals     |          5 |
    | bugle      |          6 |
    | violin     |          7 |
    | harp       |          8 |
    | bagpipes   |          9 |
    | oboe       |          9 |
    +------------+------------+
    14 rows in set (0.00 sec)

    Let’s list all the percussion instruments sorted on the name:

    mysql> SELECT instrument FROM instruments
       
    ->  WHERE type = "percussion"
       
    ->  
    ORDER BY instrument;
    +------------+
    | instrument |
    +------------+
    | drums      |
    | timpani    |
    +------------+
    3 rows in set (0.00 sec)

    You may be wondering, “Can I reverse that order?” Yup, using the qualifierDESC .

    mysql> SELECT instrument FROM instruments
       
    ->   WHERE type = "percussion"
      
    ->   
    ORDER BY instrument DESC;

    +------------+
    | instrument |
    +------------+
    | timpani    |
    | drums      |
    +------------+
    3 rows in set (0.00 sec)

    More Perl Articles
    More By Apress Publishing


     

    Buy this book now. This article is excerpted from chapter 15 of the book Beginning Perl (Apress; ISBN: 159059391X). Check it out today at your favorite bookstore. Buy this book now.

       

    PERL ARTICLES

    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway