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

NOT BETWEEN - 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

Likewise, if you wanted to see a list of employees whose salary was NOT between $75,000 and $100,000, you would use the NOT BETWEEN statement. This would show you any value lower than $75,000 and higher than $100,000.

SELECT * FROM EMPLOYEES WHERE SALARY

NOT BETWEEN $75,000 AND $100,000;

This would show us the following table:

 

First Name

Last Name

Position

Salary

Bruce

Lee

Security

$50,000

Your

Name

Whipping Boy

$15,000

ALIAS

I know what you are thinking. Hot girls in tight leather pants using high-tech weaponry and kicks to the face to spoil the plots of evil-doers worldwide, and still somehow managing to form meaningful relationships. And all within one hour no less.

Unfortunately, SQL doesn't have any of those. If it did, then every program would be written in SQL. Imagine the database version of World of Warcraft. (Hmmm, now where did I put my medication?)

The ALIAS statement in SQL comes in handy if you want your column names or even your table itself to show a different name than you originally gave it, without having to change the name of anything. A lot of times you will have other programs that refer to your tables, and if you change the table name or the columns, you have to change all that code. Not good. This is where ALIAS comes in handy.

SELECT FirstName AS Ninja_Warrior, SALARY AS Meager_Earnings

FROM EMPLOYEES;

This would take the first name and salary columns from your employees table and display them with the names Ninja_Warrior and Meager_Earnings, respectively (without actually changing them and causing you many hours of headaches).

Ninja_Warrior

Meager_Earnings

Larry

$100,000

Homer

$75,000

Homer

$75,000

Liza

$85,000

Bruce

$50,000

You

$15,000

Again, you can do the same with your table.

SELECT FirstName, SALARY

FROM EMPLOYEES AS EX_EMPLOYEES

This would return the first name and salary of your employees and show them in a table called EX_EMPLOYEES.

That covers the first part of the more advanced commands contained within SQL. In the next and final tutorial we will delve into the rest of the advanced statements and transform you into a true SQL Master.



 
 
>>> 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: