SQL Tutorial Part 1: Fundamentals

The basic concepts of SQL can be explained in the context of this question:

What is SQL used for?

While the answer can be complicated; for non-technical data consumers like Product Managers it is actually quite simple:

SQL is used to convert a large volume of data into a digestible format.

What do I mean by that? Let’s elaborate with an example:

Suppose I run a company that makes and sells candles. The company offers three different sized candles and each size sells for a different price: $1 for a small, $2 for a medium and $3 for a large. The company keeps a list –called a Table – that records all candle sales, with one line – or Row – for each candle sold. Each row includes details about the sale, in this case: (1) the Date the candle was sold, (2) the Size of the candle sold, and (3) the Price the candle sold for. All of the entries for any one detail type form a Column. For example: all prices for all candles sold form the Price column. So, if I want to know the company’s revenue, I just add all of the entries in the Price column and the result is revenue.

No problem! Right? Well, let’s consider three different scenarios:

  1. The company sold three candles last year: No SQL required here. I can just add the three Price entries in my head.
  1. The company sold 15,000 candles last year: No SQL required here either. I can just copy and paste the entire table into Excel, then add up the Price column.
  1. The company sold 23 million candles last year: OK, now I need SQL. I cannot add 23 million prices in my head, and 23 million lines (rows) is too many to fit into Excel (Excel without add-ins can fit just over 1 million rows). The easiest way to answer this question is to use SQL to specify the exact information that I need from this table. The only alternative is to try to analyze all 23 million rows directly, which is impractical if not impossible.

Now that you know why you need SQL, let’s find out how to use it!

Leave a Reply

Your email address will not be published. Required fields are marked *