HomeBrainDump 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.
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:
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
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).
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.