Friday, February 17, 2012

SQL Excitement (So what in the world is SQL?!)

Tables, columns, rows
Single-table queries, multiple-table queries
Queries, queries, queries

So what is  a query, anyway?!
Glad you asked!

A query is a question represented in a way that a Database Management System (DBMS) can understand. ¹A Guide to SQL, 8e; page 98.

What this really means is that you can ask (pull) specific information that you want or need from a database table or collection of related tables without showing all the information. For instance, in an address database you might want all the people who live in GA, or all the people within a certain Zip code area, or all the people in GA that live in a certain Zip code. If your fields (columns) were detailed enough, you could ask for all the married couples, or all the single people, or perhaps all the people that have an email address that are married. You specify the criteria or conditions to be met, sort by the field you chose, and pull up the exact information you desire.

But how would you use  this - what is the purpose of a query?

This is when it starts getting fun!

Suppose you had an address database with over 2,000 names, address, phone, emails, etc., and you wanted to mail out Christmas cards to everyone who did NOT have an email address AND who lived within the United States. Also, you wanted a list of everyone who had an email address so you could send a Christmas letter to them via email.

Yes, you could query the specific criteria (conditions) and get exactly what you wanted!

Ah, and those are simple  queries...

Suppose you were a business with over 18,000 items in your inventory... this is when queries really  get fun!

You could find out how many items you had on hand, in which warehouse, sorted in alphabetical, price, or number-on-hand order - your choice - how many times an item was purchased per month/year, etc. You could determine the average sales per month, the item that sold the most per month, the store who sold the most inventory, which sales clerk had the most sales or earned the most commission. You could query to find all the customers whose balance was over their credit limit, or who owed you a late fee... You can do so much with queries!

To put it all in a nutshell: a query is used to pull information from a database table, or set of tables, in order to find or calculate results in a specific order, for a specific use or purpose.

Does that make sense? If not, I an highly recommend my course textbook!! LOL

My conclusion? I love SQL!!!

   
¹ Last, Mary Z.. Pratt. Philip J.. A Guide to SQL, 8e. Boston: Course Technology, 2009.

No comments:

Post a Comment