BrainDump
  Home arrow BrainDump arrow Beginning SQL the SEQUEL: Working with Advanced SQL Statements
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 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? 
BRAINDUMP

Beginning SQL the SEQUEL: Working with Advanced SQL Statements
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    2007-09-26


    Table of Contents:
  • Beginning SQL the SEQUEL: Working with Advanced SQL Statements
  • AND and OR...Or OR and And
  • The IN-credible Statement
  • NOT BETWEEN

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Beginning SQL the SEQUEL: Working with Advanced SQL Statements
    ( Page 1 of 4 )

    So you made it through the first tutorial and now you are back for more. Well buckle up for the ride, because this episode teaches you the glories of advanced SQL statements. By the end of this article you'll be able to sort data, join data, you name it.

    That's right, hordes of rows and columns will be at your mercy. You won't only know SQL -- you'll be SQL. So slap on your cool shades and trench coat and get ready to dodge bullets in slow motion. And prepare to become the one.

    Disclaimer: You won't actually be able to dodge bullets after reading this article. You will however be able to avoid being shot at by your boss when you show him your l33t programming skillz.

    Sorting Things Out

    Before I became a big, illustrious writer with oodles of fans, I worked for a boss who liked to sort everything. Even if it couldn't be sorted, he wanted me to sort it. Hours on end he would call me into his office imploring me to sort by name, date, value. And off I would scurry to do his bidding. Then one day he began to ask me to sort things around his office. Like his garbage can and the stapler. Last I heard he was in a small room with a white jacket. They say when the nurses come to bring him his pills, he whispers softly, "Can you sort those for me?"

    To sort in SQL, you will need a handy little phrase called the ORDER BY statement.

    SELECT FirstName, LastName from EMPLOYEES

    ORDER BY LastName;

    In the above code, we are telling the database to choose and display the columns FirstName and LastName from our table, Employees, and to then sort them alphabetically by the last name.

    If you wanted to sort the same two columns in reverse alphabetical order, then you would do so by adding DESC (descending) to the code.

    SELECT FirstName, LastName from EMPLOYEES

    ORDER BY LastName DESC;

    You can, of course, also sort by more than one column. Say you wanted the first name, last name, and salary of every employee, sorted first by last name, then by salary.

    SELECT FirstName, LastName, SALARY from EMPLOYEES

    ORDER BY LastName, SALARY;

    And finally, for a last bit of sorting madness, if you wanted to sort by LastName in Ascending order and SALARY in Descending order, you would grab a safety helmet and type in the following code:

    SELECT FirstName, LastName, SALARY from EMPLOYEES

    ORDER BY LastName ASC, SALARY DESC;



     
     
    >>> More BrainDump Articles          >>> More By James Payne
     

       

    BRAINDUMP ARTICLES

    - Demystifying SELinux on Kernel 2.6
    - Yahoo and Microsoft Create Ad Partnership
    - The Advantages of Obscure Open Source Browse...
    - Dell Announces CSI-style Digital Forensics S...
    - Milepost GCC Speeds Open-Source Development
    - Learn These 10 Programming Languages
    - Tomcat Capacity Planning
    - Internal and External Performance Tuning wit...
    - Tomcat Benchmark Procedure
    - Benchmarking Tomcat Performance
    - Tomcat Performance Tuning
    - Wubi: Windows-based Ubuntu Installer
    - Configuring and Optimizing Your I/O Scheduler
    - Linux I/O Schedulers
    - Advising the Linux Kernel on File I/O





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT