From the course: SQL for Non-Programmers

Getting started with SQL - SQL Tutorial

From the course: SQL for Non-Programmers

Getting started with SQL

Welcome to the fun part. Let's begin coding with your first SQL commands. We will be analyzing data from the fictitious company Two Trees Olive Oil, a family-based company out of California that sells premium quality olive oil across the United States. We are going to start working with only one data table covering their business sales. Later in the course, we will advance to working across multiple tables. Let's kick off with a simple query and build up from there. We are working with the management team who is requesting order reports and wants to understand how the sales team is performing. We will be using the Select statement to retrieve data from our tables so we can answer their questions. The Select statement is actually the only statement within the data query language command family, making the programming language quite accessible as you will soon see. The Select statement needs, at minimum, two pieces of information: what data you want to select and from which tables you want to extract that data. Within the select statement, you can specify the columns you want to retrieve and use the From clause to indicate which table you want to access. To see this in action, let's move over to SQLiteStudio, which I will be calling SLS, moving forward. We will start with the database we set up previously. If you open the database file attached to the introduction chapter, your database in SLS should look the same. We can expand it here by double clicking oliveoil. The arrows can be used to expand or close each section. We have three tables available in our database: employees, regions, and sales. If you click the side arrow next to a table, you can see more information about that table, most importantly, the columns of data included. The employees table has three columns available: ID, name, and job title. The regions table has two columns available: state and region, and the sales table has this long list of columns available. Let's close the employees and regions tables for now by selecting the arrows next to each. In case your database window is not large enough to see the column names, keep in mind that you can drag the side of the window to make it larger or smaller. The right hand side of SLS should look similar to my screen by default, with three white boxes for query, grid view, and status. This is your SQL code editor. You can see the window in the bottom left hand corner which is labeled SQL editor 1. You can even rename it by right clicking and selecting Rename selected window. We are going to call this SQL Practice. Click the Okay button once you have typed that in. In case you accidentally close out this window or it is not appearing for you by default, no problem. Let's simulate what that would look like and reopen the SQL editor. I am going to close our SQL Practice window by right clicking on the bottom left hand side and selecting Close current window. To reopen a SQL editor, click the symbol that looks like a paper and pencil across the top toolbar. You see, when I hover over it, it says, Open SQL editor. I am going to rename this again, SQL Practice. You can have multiple SQL editors open simultaneously, although I will stick to using one window throughout our course. Your screen should look like this now, which means we are ready to get started. We are going to begin each coding chapter by opening the exercise file that it corresponds to. In order to do that, click the yellow folder symbol across the second toolbar. You see, when I hover over it, it says load SQL from file. I have my exercise files downloaded and saved on my desktop. Select the exercise files, then chapter two, and then chapter two part two. In order to open these text files in SQLiteStudio, we need to change the file format across the bottom from SQL scripts to all files, because we are using text files. Each of the chapters throughout our course will have a begin and end file. Make sure to always start with the begin file. In this case, select 02_02_begin and click the blue open button. So we are ready to get started in the next chapter. I'm going to make our query window slightly bigger by dragging down the bottom of the box. Finally, it's time to code. Let's learn more about the magic behind the Select statement.

Contents