Categories
SQL

SQL: Introduction to SELECT statement, analogy for beginners


SELECT statement

I have worked with numerous non IT professionals including medical doctors, accountants, actuaries and accademics who have had to extract the data they need using SQL from relational databases. I firmly believe that if you understand the objective or bigger picture of a language term, you will be a more effective user of the term. Here is the analogy I use to introduce the SQL SELECT statement to SQL beginners and non IT data analysts. The better your understanding of the term the easier it will be for you to debug SQL statements generating errors.

Imagine a database being a mall, a collection of shops in one building. You need to buy a some items and you compile a shoping list because your memory is not as good as you think it is:

  • Bread from the baker
  • Cake from the baker
  • Sausages from the butcher
  • Towel from the linen shop

In SQL you should think of the SELECT statement as your shopping list. It has to be precise because for example bakers sell more than just bread. They also sell muffins, cup cakes, bagels, etc. You need to pick what you want, in this case bread and a cake, from an array of items available in the bakery. Similarly when using the SELECT statement in SQL you have to be specific about the columns that you want from the table. Realistically you are not going to find towels being sold by a bakery and similarly in SQL if you try and select columns not in table you will get an error.

FROM statement

The FROM statement is used in conjunction with the SELECT statement and specifies from which table column(s) should be selected. The FROM statement does not differ in meaning when used in SQL to when used in conversation. I imagine a shopper reporting back after some shopping at a mall, “I bought some bread FROM the bakery and some sausages FROM the butcher”. In a database the shops would be called the tables. Hence the FROM statement is always used to specify from which tables data must be selected.


Leave a Reply