Home arrow BrainDump arrow Page 3 - Beginning SQL the SEQUEL: Working with Advanced SQL Statements

The IN-credible Statement - BrainDump

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.

TABLE OF CONTENTS:
  1. Beginning SQL the SEQUEL: Working with Advanced SQL Statements
  2. AND and OR...Or OR and And
  3. The IN-credible Statement
  4. NOT BETWEEN
By: James Payne
Rating: starstarstarstarstar / 11
September 26, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

BRAINDUMP ARTICLES

- Apple Founder Steve Jobs Dies
- Steve Jobs` Era at Apple Ends
- Google's Chrome Developer Tool Updated
- Google's Chrome 6 Browser Brings Speed to th...
- New Open Source Update Fedora 13 is Released...
- Install Linux with Knoppix
- iPad Developers Flock To SDK 3.2
- Managing a Linux Wireless Access Point
- Maintaining a Linux Wireless Access Point
- Securing a Linux Wireless Access Point
- Configuring a Linux Wireless Access Point
- Building a Linux Wireless Access Point
- Migrating Oracle to PostgreSQL with Enterpri...
- Demystifying SELinux on Kernel 2.6
- Yahoo and Microsoft Create Ad Partnership

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: