BrainDump
  Home arrow BrainDump arrow Page 3 - Beginning SQL the SEQUEL: Working with...
The Best Selling PC Migration Utility.
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 
eWeek
 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: 5 stars5 stars5 stars5 stars5 stars / 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:
      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

    Virtual Tradeshows by Ziff Davis Enterprise - A Unique Opportunity to Connect with IT Experts, Access Information, and Gain Insight on today's Technology

    Beginning SQL the SEQUEL: Working with Advanced SQL Statements - The IN-credible Statement
    (Page 3 of 4 )

    By now you may have noticed that there are multiple ways to return the same results in SQL. This is true for all languages really. With the IN statement, you can retrieve a specific set of data you are seeking.

    SELECT * from EMPLOYEES

    WHERE LastName IN ('Sampson','Lee');

    With this line of coding, we are asking the database to return all rows that contain the last names of Sampson and Lee. I know what you are thinking; we could have done that with the OR operator or even the AND operator. Right you are. So why use IN? It's just a matter of preference.

    BETWEEN AND

    You have probably been between a rock and a hard place before, but that's not really what the BETWEEN AND statement is about. If you think about being asked to choose a number between 1 and 100, you're much closer to understanding this bit of SQL. The basic function of the BETWEEN AND statement is to allow you to choose a range of values.

    Let's say you wanted to list all of the employees who made between $75,000 and $100,000. To do so, you would use the following code:

    SELECT * from EMPLOYEES WHERE SALARY

    BETWEEN $75,000 AND $100,000;

    That should bring up the following table:

    First Name

    Last Name

    Position

    Salary

    Homer

    Sampson

    CEO

    $75,000

    Homer

    Sampson

    CFO

    $75,000

    Liza

    Sampson

    CTO

    $85,000

    Larry

    Smith

    President

    $100,000

    Note that in some databases, the BETWEEN AND Statement is taken more literally and would not find $75,000 or $100,000, but instead any number between them. In that event you would change the parameter to between $74,999 and $100,001.

    More BrainDump Articles
    More By James Payne


       · This is the second SQL article in my series of Beginning SQL. It covers working with...
       · Even though I use some SQL, these articles give an easy to read overview and...
       · Nice to know that learning SQL, can be fun , literally.
       · Thanks for the kind words; I'm glad you guys enjoyed it.
     

       

    BRAINDUMP ARTICLES

    - Outsourcing: the Hoopla, the Reality
    - MySQL Plays in the Sun
    - All About SQL Functions
    - SQL: Functioning in the Real World
    - More Advanced SQL Statements
    - Beginning SQL the SEQUEL: Working with Advan...
    - Beginning SQL
    - A Look at the VI Editor
    - A Quick Tour of Boo
    - Book Review: Open Source Licensing
    - PGP and GPG: Email for the Practical Parano...
    - Microsoft Continues War on Open Source
    - Secure Remote Desktop Sharing with VNC on Li...
    - A Look at Google Project Hosting
    - What we can Learn from Two Linux vs. Microso...




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