Day 2 of losing my SQL sanity…
Okay, I might be exaggerating a tiny bit. To be completely honest, it still isn’t too bad. My teacher, Chris, says we still haven’t got to the fun part: Joining Tables and modifying tables.
Before I truly begin, you need to know a few things: “Select”, “From”, “Top”, “Order By”, and “Distinct”. I know you’re asking, “Water Thooose?”, and the answer is: Google it. These are really simple statements that I’ll actually explain so you don’t have to do any work :) You’re welcome! “Select” defines what column one wants to call upon. “From” defines which table you want your query to run in. “Top” orders the data based on the top results; it may be top 100, top 1000, etc. “Order by” orders the data based on the users requirements. “Distinct” calls upon data that is shown multiple times, and smashes it into one result so that there is no repeats. Now we can start with today’s lesson.
Today, we learned of things such as “Where” Clauses (Hohoho!), Complex “Where” Clauses and Sub-Queries. Now that you have a basic idea of what I learned, let’s get to know more about these SQL subjects.
“Where” Clause: What, When, Where, Who, Why? What is the “where” clause? It is a way of specifying the results one is trying to call upon. When do I use the “where” clause? One would use it when they are trying to find a specific result, such as “Where Kittens = ‘Too many'” and it would find a column called “Kittens” and call a result shown as “Too many”. Where does this clause go? One would use this clause below the from statement. Who actually uses this clause? Anyone who has and ever will be involved with T-SQL. Why should I use this clause? I would tell you but I feel that it’s relative. Trust me, you will use this clause.
There are Conditions, and Operators and Wildcards and all kinds of fun stuff used along side the “Where” statement. If you want to specify your “Where” even more, you are going to have to use “Operators” such as, ” ‘=’ , ‘!=’ , ‘<‘ , ‘<=’ , ‘>’ , ‘>=’ , ‘<>’ , and ‘BETWEEN’ ” For the Operators, you’re actually going to have to look them up if you want to know what they mean and do. “Wildcards” are fun and replace values with random characters. One would usually use them when they want to find a value that starts with a certain character, but they don’t care what it ends with. There is a “Not” statement which does exactly what you think. It does the opposite of what you want. For example ” where FirstName NOT = ‘John’ ”
“Null”… This statement could probably have its own blog. Null is not zero. “Zero” is a value. Null is not an empty cell. Empty cells have a value. Null is literally nothing. Null has no value. Don’t confuse it with a zero or an empty cell.