Beginning SQL the SEQUEL: Working with Advanced SQL Statements - NOT BETWEEN (Page 4 of 4 )
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.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |