SELECT FROM... the first blocks

SELECT FROM... the first blocks

Taking your first SQL steps

If you're like me and almost every data professional out there, the first SQL query you will ever write will involve two statements (yes, they are called statements); SELECT and FROM. These two statements are universal and applicable across all Relational Database Management Systems (RDBMS).

SELECT date_of_purchase
FROM orders;

The SELECT statement is used to choose the columns or data you want retrieved from a table. It can take as many columns as you need. The FROM statement is used to specify the table the data will be retrieved from.

For example, you work at an e-commerce company and your boss wants you to retrieve 4 columns: date_of_purchase, shirt_qty_sold, trouser_qty_sold, and total_amt_usd from your orders table for further analysis, you can write your SELECT statement like this:

SELECT date_of_purchase, shirt_qty_sold, trouser_qty_sold, total_amt_usd
FROM orders;

When writing queries, it's good practice to write your statements and keywords in upper case for code readability and clarity.

Note: The column names are separated by a comma. This query will give you all the data from these 4 columns

Perhaps you want to select all the columns in the table without specifically writing out all the column names, you can use the * key

SELECT *
FROM orders;

This query will return all the columns from the orders table.

SELECT and FROM statements are the backbone of every SQL query you will ever write, from beginner to advanced levels. Get used to them. Till we meet again

Your partner in data, komoni