SQL Full Course Tutorial
Transcript
Data nerds, welcome to this full course tutorial on SQL. This is the video I wish I would have had when I first got into data engineering. To master this tool, we'll break down concepts into short five to 10 minute topics. You'll work right alongside me completing real world exercises to learn not only SQL, but also other in-demand skills like terminal Git and GitHub. After each short lesson, you'll have the option to tackle interview level practice problems that prep you for the job and reinforce your learnings. And by the end of the course, you'll have built two fully customizable portfolio projects that showcase your skills in building and analyzing a production level data warehouse pipeline. Now, SQL is by far the most popular tool for data engineers. If we look at recent job postings, we can see that it's in two out of every three postings for data engineers. And it only increases demand for those senior roles,
making it even more of a vital skill to learn first. Now, SQL or SQL is the language used to communicate between you and a database. It's by far my most used tool as a data nerd, starting with my first job working for a global fortune 500 company all the way to my most recent job working with Mr. Beast. Yeah, even Jimmy uses it. More recently, I've been using it in my data pipeline for my app data nerd tech, but more on that in a bit. So over the years, I've cataloged everything that's essential in using SQL and bundled it all up into this course. Now, to be clear, I've made this for beginners. There's no coding terminal or even engineering experience required. I'll be teaching you everything you need to know step by step for this. We're going to break up the course into two halves with the first half focusing on the fundamentals you need to learn to feel confident writing SQL in a real data engineering workflow. We'll start by getting
your environment set up and making sure you can run SQL both locally and in the cloud. Then we'll introduce core query building blocks such as filtering grouping aggregation and sorting data. From there, we'll shift into understanding how data should be structured in warehouses with dimensional modeling. And throughout the sections, you'll use the same tools real teams use of VS code, the terminal and get in GitHub. At the end of this first half, you'll build a portfolio ready project where you explore a real data warehouse. In it, you'll write SQL scripts to answer stakeholder style questions and your analysis will be published to GitHub. And this will ultimately help you start thinking like the stakeholders will be building data pipelines for. Now, in the second half of the course, we'll shift into writing SQL the way data engineers use it in production. We'll start with how they build and evolve warehouse tables using create, alter, and drop.
We'll then cover how pipelines load and maintain data with insert, update, and delete. From there, we'll focus on data modeling techniques, especially star schema design of fact and dimension tables. So your warehouse is built for analytics and downstream use. And finally, you'll level up your SQL with CTE and sub queries for clean modular scripts, plus window functions for real warehouse analytics and pipeline logic. At the end of this half, you'll build a production style end-to-end SQL pipeline, designing the tables with a correct schema, and then loading the raw data into it, and then producing data marks for specialized use cases that can be accessed by a multitude of tools and prove your job ready data engineering skills. Now, I believe in open sourcing education. So this entire course is completely free. You'll have access here on YouTube to every video lesson and can follow along with exactly what I do. And everything we're using to run SQL is completely
free and open source. Oh, and I've even made both final projects publicly available so you can compare your work to it. Now, for those that want to support the course, I have some perks that add structure, practice, and certification. First, you'll get access to your own course dashboard that tracks your progress. In here, it lets you watch each lesson individually in short bite-sized segments. Then after each lesson, you'll have access to additional SQL interview level practice problems that provide a detailed solution. However, you get stuck, you can leave a comment below and get help from other students. On top of this, I'm giving you all my course notes that walk through the video lessons step by step, and you'll get access to my custom cheat sheets breaking down key concepts. When you complete the course, you'll receive a certificate of completion that you can post directly to LinkedIn. So if you want to support and bring to life more courses like this,
use the link in my description to get access to the supporter resources. Now, I have two SQL courses, SQL for Data Analytics, my first SQL course. It's four hours long and ends with an analytics focus project. And then this course, it's 14 hours long, and it has a similar analytics project, but then an engineering focus project as well. So which one should you take? The simple answer is data analysts should take the first course and data engineers should take this one. Now, neither course is a prerequisite for the other. Both courses teach the same SQL language, but they implement it differently. SQL for Data Analytics focuses on querying existing data to answer business questions. And then this course starts similarly, but it ultimately focuses on building production level pipelines, framing this all from an engineering perspective. If you've taken SQL for Data Analytics and want to take this one, go for it. You'll still benefit early
sections may feel familiar. So skim ahead if those concepts are already solid. Now, this course was a behemoth to me. So for 14 hours long, it took me the greater part of last year to make. And it took a team of four to put it all together. So I'd be remiss if I didn't give a shout out to these teammates. For this, we're going to do it the office style. Ricky, my content developer, did a lot of work behind the scenes putting together those SQL interview practice problems, ran in my video editor help condense down about a hundred hours of video footage into 14 hours. And finally, Kelly was the producer of the course, helping out with both lesson and interview practice problems. So shout out to my team for helping me bring this together and make this course possible. All right, one last thing before we jump into the course, if you get stuck along the way, I highly recommend you use any popular chatbot as they're more than proficient in SQL and a
heck of a lot faster than waiting on me to reply. Anyway, enough of me, Evan, let's get into this course diving into our first concept to understand what SQL actually is. All right, in this lesson, we're going to get you up to speed in understanding everything you need to know behind this powerful tool for data engineers. To understand this, we need to grasp two major concepts. First, where do you write and execute your SQL queries? And secondly, your database, where your data's actually stored. So let's dive into that first. A database is a collection of data. And these things were made to hold a massive amount of data. An Excel file spreadsheet can only hold around a million rows, but a database can easily hold way more than that nine quintillion rows. Now about those databases, there are two main types of relational and non-relational. We'll explore each type more in a bit. But first, let's go back to where we're actually running SQL.
When you write this code to request data from a database, that's called a query. And SQL can do a whole heck of a lot. A common acronym associated with this is CRUD. And it stands for create, read, update, and delete. With SQL keywords like create and insert into, you can add new records. Then with keywords like select, you can retrieve specific data you want. Next, with keywords like update, you can modify existing records. And then finally, the scariest of all, you need to remove records, you can delete it. Now these commands fall under three types of SQL commands. DQL or data query language is used for the reading aspect of CRUD. And is what we'll focus on on the first portion of the course. Next is DML or data manipulation. And this is used for creating, updating, and deleting new data, specifically in tables that already exist. Then we have DDL, which is data definition language. And this deals with creating or deleting the schemas and
tables we need from scratch. So understanding this, we can now understand how SQL actually works. From your computer, you write a SQL query and send it to a database. The database then performs your CRUD operation and then provides you a SQL output, depending on what you did to your computer. But this now begs the question, where are databases even stored? Well, there are two main options. You can either run it locally or in the cloud. Local means the database runs directly on your computer. This is ideal for data engineers to iterate quickly without affecting production databases. However, others can't access it. Now production databases are usually stored in the cloud. This enables your entire organization to connect to the data source you built. You probably heard of popular cloud providers like Google, Amazon, or Azure. Anyway, we're going to be using a combo of both local and cloud for this course. And in the final project, you'll be building out a
data warehouse and data mart locally, and then push it to the cloud to make it publicly available. So now that we understand that databases can be stored on your computer or in the cloud, what are the different databases we can store in these locations? Well, two main types of relational and non-relational relational databases store data in rows and columns, very much popular in analytical applications. Say of a database, a job posting that companies go to daily to update on what jobs are available. You could have one table to keep track of all the different jobs, and then you have an associated table to keep track of all the different companies. There would then be things like a company ID within the two in order to relate the different tables. Hence, relational databases. Now, this course will primarily focus on using SQL to interact with relational databases. But it's important to know the other type of database of non-relational
databases, commonly known as NoSQL. But NoSQL doesn't stand forward, not SQL. It stands for not only SQL. These supports storing your data in a variety of different forms, including key value paired, column based, graph based, and even document based. Alright, so we understand the types of databases now, because of that, we can get into narrowing down what database we're actually going to use for this course. Well, I needed to meet a few criteria. First of all, it needed to be a relational database that was also highly popular. So it has community for support. From there, I started to narrow it down to a database focused on analytics to make it support building data warehouses. After this, I narrowed it down to free and open source options so that anybody taking this course can use the database. And finally, with that, I needed this database also to run locally first, along with the cloud. And so this gave us DuckDB. DuckDB is a blazingly
fast database that satisfies all of our needs. So we're going to be using it for the entirety of this course. We're not only going to get you set up with running it locally on your own computer, but we'll also run DuckDB in the cloud by using mother duck. This is a managed cloud platform that will be completely free to use as well. Now this brings us back to the last concept we need to cover of where we're going to be writing and running these queries. Well, that's commonly done in an editor, whether that's database provided, cloud provided, or just a standalone code editor. Now database provided ones provide you with an application to use on your computer to access their local database or cloud based one. This is a popular option from Postgres called PG Admin, and inside it even allows you to write SQL queries. For data engineering work, I'm not a fan of these. Next up are cloud provided editors. Typically, you access them in a web browser and they allow you
to interact with your database. We're going to be using mother ducks cloud provided editor in order to connect to our needed databases for the course. We'll actually do this for the first half because it's super easy to get up and running for you. Last up are code editors. And this is what we'll focus on for the majority of the course. We're going to be using a popular option of VS code along with the terminal, which allows you to build all your SQL files locally, but then interact with databases that are either local or in the cloud. You'll be running SQL queries like a pro data engineer after this. Alright, so now we understand what SQL is and what tools we're using for the course. But it now begs the question, what data we're going to be using and what pipeline are we going to be building for this course? Well, covering that next. Welcome to this lesson. We're going to be diving into understanding what data and also what pipeline we're going to be building
for this course. But before we talk about any of that, we need to understand what problem we're trying to solve. And it's a real problem that I had. This all started a few years ago when my subscribers were asking what are the top skills they should be learning in data. And the best way to answer this analytical question is to look at where these skills are demanded in job postings. So I built out a data pipeline that solves this. It pulls online job postings from a source and then using SQL cleans up and transforms this data. Finally, it then loads it into a data warehouse. Now I'll go into this data source and how I built the pipeline in a bit. But first, what's a data warehouse? Well, in order to qualify, it needs to be subject oriented, non volatile, integrated, and time variant. If it doesn't have these four things, it's just a database and not a data warehouse.
This is all from the father of the data warehouse, Bill Inman, and we'll be going over this definition in much more detail as we build out our projects. Anyway, for our final project, we're going to be replicating what I did by taking raw job postings and building out a data warehouse and also data marks all with SQL. So what does this data look like inside of our data warehouse? Well, here is an ERD or entity relationship diagram, and it shows the different tables in here. We have four major tables, one fact table containing all our different job postings, then a dimension table around the different companies that are posting jobs, and finally, dimension tables that contain key information about the skills required for these jobs. Now, if you haven't heard about fact tables, they contain the core data for our analysis. They measure and record actual events. So in our case, the different job postings,
the dimension tables describe attributes or dimensions of the data. In our case, skills and company information, and this is really important to supporting filtering and grouping different sets of data. Anyway, that's all theoretical. Let's actually dive into my machine and look at the key attributes from the data. So querying this data warehouse, we can see that we have 10 different jobs available to look at job postings for data analysts, data engineers, and data scientists are by far the most popular, but there are other options available. And with that, these postings come from around the world in over 160 different countries. So the country you live in probably is in this data set, and this now begs the final question of what platforms did we get all these job postings from? Well, a ton of popular options like LinkedIn, indeed, and even Zippercruiter. So you're probably wondering, where the heck did
this data come from? Honestly, it wasn't easy. Back in 2022, I wanted real data on what skills actually get you hired and data jobs to provide to my subscribers. Not opinions, not blog posts, but real job postings. So I did what any data nerd would do. I tried to scrape LinkedIn. So over the course of a few days, I built a scraper, learned just enough front end to make it work, stayed logged in with my LinkedIn account. And surprisingly, it worked. Well, for about a day. Then the captures started to hit. Then my account got banned, and it became obvious real fast. Well, job posting data is extremely valuable. And these sites protected aggressively. And this is a very real data engineering problem. Scraping at scale quickly turns into an infrastructure nightmare. So at this point, I thought the project was dead. But then I happened to stumble across SERP API, and they had exactly what I was looking for. Instead of scraping LinkedIn directly,
SERP API gave me access to job postings at scale through search engines. So SERP API can pull these jobs from Google that ultimately come from different platforms like LinkedIn, Indeed, and ZipRecruiter. So with this, I wasn't fighting captures anymore, managing accounts, or building infrastructure. On a whim, I reached out to SERP I explained my problem and asked if they could support the project. You've got mail. Surprisingly, the CEO himself replied, and they agreed to support the project. So I immediately started by jumping into their platform and building out the code in their playground area, which lets you test out different queries and see the results clicking search. I can see the search results that it gets back in this browser view. But what's actually more useful are the structured results that I get back. For example, with this first one, I can see it's a senior data engineer role in Washington DC scraped from
LinkedIn. It tells me that it's not only full time role, but also in the job description, I can see it list a host of different skills. This right here is the jackpot. Oh, and some jobs even have more information like this one with salary. Honestly, this is way more detail than I could ever have gotten by scraping on my own. From there, I can grab a code template for any popular language or tool such as curl, Python, or Google sheets, and I can run it locally or in the cloud wherever I need it. Now, to be clear, Sir PPI has way more than just job postings. They support over 50 search engines, everything from things like Google flights to Google maps to product listings on sites like Amazon. And oh, they even have an ability to look at YouTube. If I wanted to, I could scrape all of my YouTube data and get it back in only a few seconds. Oh, and if you need responses and under a second, they also offer add-ons for that. Now back to my job data. I've
been systematically pulling these job postings on a daily basis, which is how I've collected almost five million jobs over the past two years using Sir PPI. All the data can be accessed via my site data nerd tech. And it's solved my problem of figuring out what skills data nerds actually need to get hired. It's how I figured out that SQL was the most popular skill of data engineers. And all of this job posting data that I've collected of the years will be using throughout this course in order to learn SQL and ultimately build a SQL based data pipeline. Now to wrap up, I want to give a huge shout out to Sir PPI for sponsoring this video. Use my link in the description and tell them Luke sent you to get 20% off. They even have a free tier with 250 searches per month to try it out. Now enough of me happen. Let's get into setting up SQL on our computer. So we start playing around with it. All right, see you in the next one. Welcome to this
lesson where we're going to be not only going through setting you up with the environment in order to execute SQL, but also get you set up with the actual database that we're going to be using for the entirety of this course. And jumping into my computer to show you this, we're going to set you up in the browser in order to be able to execute SQL queries, you're going to have the results right below here. And you're going to have this environment here that we're working on in the first portion of the course in order to investigate and learn some different SQL syntax as we go through this. Now I'm going to get you all set up to be able to execute SQL in your browser and with the data set. Before that, we need to understand some concepts of actually where we are running this SQL query. Well, as you can recall from the last lesson, we're going to be using the free open source option of DuckDB for this course. And this is a very lightweight database that you can
run right inside of your computer. Now DuckDB is relatively easy to get set up and installed on your computer, but it requires one pretty big caveat. If I go into the installation guidelines, it tells you how to install it. And specifically, it has you installing it with a terminal. And I'm assuming for a lot of you taking this course, you don't have much familiar RRT with running commands in the terminal. And there's quite a few to get set up with not only DuckDB, but also the
data set. So because of that, I made an executive decision when making this course that we're going to start out working in this web browser environment that has DuckDB on the back end. And this is called Mother Duck. Now Mother Duck, which you can visit via this link here, is the commercial SaaS or software as a service platform that supports running DuckDB in the cloud or, if you will, in your browser. DuckDB or DuckDB Labs owns a significant equity stake in Mother Duck. So,
it's very beneficial for both of them to work together and collaborate. Mainly, they keep it separate so DuckDB team can focus on improving the database and keeping this free and open source. And Mother Duck is the commercialized version that actually makes money to keep DuckDB Labs funded. And probably the most important part that is relevant to you, Mother Duck allows us to host DuckDB databases on the cloud, basically have data warehousing capabilities. And then you can use other popular services in order to connect to these DuckDB databases inside of Mother Duck. For me coming from a data analysis background, this is pretty imperative because tools like Tableau and Power BI can connect to a single source of truth inside of Mother Duck. And there's a host of other data engineering tools that we'll eventually get into later on in the course that can connect to it as well. So to recap, DuckDB is a free open source software that you can run
either locally or on another server. Whereas Mother Duck is the platform that allows you to host these databases in the cloud, basically host data warehouses. And honestly, I wouldn't have known about either of these service. If it wasn't for Medi, you can check them out on the YouTube channel here. He heard that I was building this course on SQL for data engineering, reached out and connected me not only with the Mother Duck, but also the DuckDB team in order to put this course together and make sure it was successful. So you'd shout out to him. Now let's get into setting up your Mother Duck account. And for this, we're going to be on the free tier. We're going to remain on the free tier for the entirety of the course. And the good thing about Mother Duck is there's no credit card required. All you got to do is just sign up for those complaining that you got to sign up for a service order to take this course.
As a dad engineer, you're going to be signing up for a lot of services. And a lot of them don't offer free tiers. So consider yourself lucky with this one and get used to it. For this, you're going to navigate to the URL on screen of loopb.co/motherduck. Now the Mother Duck team has built this special login for us and the course takers of this. So that way we can skip the normal marketing emails that you get if you logged in through motherduck.com. Anyway, you'll sign up by either putting your email below, or I recommend using something like GitHub, or like I'm going to do Google. From there, go through the authentication process with Google and your associate Google account. From there, insert your name organization. I just put Luke's organization. For me, I'm located in North America. That's where I want the region to execute my different queries. And then from there, click continue. From there, you may be asked a few questions about your background.
Feel free to just fill it out or skip where applicable. And then from there, it has a let's get started. I'm going to go ahead and just click all of these and say that we did them because we're going to go through them in this. So now we're inside of the environment where we're going to be running SQL queries. Take note of this URL that where we're going to be at for executing this, so you can come back to it easily. Let's get into understand the UI or user interface of this mother duck experience. Now it's broken into three major parts. Over here on the left is what you'll hear me call the left sidebar, the sidebar in the middle right here is our SQL notebook. And we can actually add different notebooks as well in that sidebar. But that's where we're going to be executing those SQL cells, which we'll get into a little bit. And then we also have on the right hand side, something called an inspector, which we can go into inspect data sets.
I'm going to leave that open for the time being so that we can get into that. We'll go back to that mother duck notebook right here. Let's dive into that left sidebar a little bit further. They have capabilities do search. So if you have a certain term, you can search for it. We can also create tables from files. Then in that notebook section, I can either hide or show it. We just created this untitled notebook. I'm actually going to rename this notebook. And we'll just name it after what this section is specifically, we'll call this SQL and database setup. And then I'll click rename. Feel free as we go through these different lessons to create different notebooks to keep track of what we're doing underneath these notebooks are our attached databases. And right now we only have two. We have a my database and nothing inside of it. And then we have some sample data sets. And we'll explore one of these to explore a notebook here in a second. But I want to call out this
down at the bottom, you may see something this of, Hey, your trial ends in 21 days. Don't worry about that. You will stay on that free plan. And the course will or this platform will be continue to be free to the entirety of this course. You're not going to use enough resources to need to upgrade. So don't worry about that. So I'm just gonna minimize this. Before we dive into those databases, it's important that we understand how hierarchy works in a database, specifically for tables and different data we have inside of it. So for a database, you can have one or multiple different schemas. We're just simplifying it here, but only allowed to have certain tables within that schema. So schema a in this case could have table one, two, and three, such as users, orders, and products, and then table or of schema B could have something like employees and products in a separate
one, you can keep it separate from each other. But in the same database, we'll apply this to our data set that we're going to be using for this course in a bit. But I wanted to go over that because if we look inside of here, we have something like my DB, and it has the schema of main. Similarly, underneath the database of sample data, it has 123456 different steam schemas. And then if I go to something like the stack overflow survey, it has two different tables inside of that schema. So what I'm gonna do is I'm gonna go to that survey results of the stack overlay survey. And what I can do is click these three dots right here. And it allows me to query in the curtain notebook. I'm in the welcome to mother doc. That's fine. I'm just gonna go ahead and do it. And it puts it down here at the bottom. Now we're gonna get into actually understanding the SQL dialect here in the next lesson. But I want to show you that you don't even know, know any SQL in this program, and that you
can just query it using the actual UI. And it puts in all the relative information, all these different column names for this data set, a lot of columns in this one. And then down at the bottom, it provides a table view of this. And I can go through and see all the different values in it. And also scroll down because it returned, I can see from up here, 100 rows returned, and 374 milliseconds, Dr. B is super fast. If I wanted to, I could copy the results to my clipboard, or even download the results to some different file formats. Now what's cool about this UI that I really like, is that over on the right hand side in this inspector window, I can go through and view all the different columns right here. And it provides some EDA or exploratory data analysis for me to actually dive into it. So looking at something like the country column, it tells me that there are 28 distinct values.
And it shows a bar chart with this, how it relates to the other columns and how many distinct values it has. And we can scroll through and see any different columns of one. This, as like I said, this is a lot of columns in it. So this is great for someone that wants to actually look through a lot of different columns. Now besides viewing columns right here on the inspector, you can also view it down below here. If I just click survey results right here, it will appear right underneath it. And once again, I can actually in this case, we can see that there's a difference here, right? This one, because we only queried 100 rows, 100 of all the different rows that they have, it only showed 28 columns. But over here on the left, because this one actually queried all 615,000 rows, it has different results. And it says we have 264 different countries. So make sure you understand what we're actually querying whenever you're viewing this, neither one of the windows.
Anyway, I can also go into and dive into seeing a deeper dive on any one of these as well by just double clicking on it. So if you notice, when we're going through that, none of that jobs data that we're going to be using for the course is located in here, we actually need to attach that database. So we you have access to it. So what we're going to do is we're going to navigate over to this notebook that we're going to work in for the remainder of this lesson. That's on that 1.1 SQL and database setup that we created inside of here, inside the notebook, we're going to add a cell. Now we're going to run an attach command in order to attach a database. Specifically, we have to specify this long line in there. So I'm not going to expect you to actually type that in. I'll include it in the description below for you to just copy and paste into here. And this is actually specifying
that data jobs database with a unique identifier. From there, we're going to run our first cell by pressing either this button up here, this play icon, or we can press in my case on a Mac, on press command enter. Now we can see up in the left hand corner, is my data jobs database. It has only one scheme in it of main and then four different tables. Company down, job postings fact, skills down and then skills job down. So in our case, this is what the database hierarchy looks like.
We have our schema of main and then those four tables underneath that schema. This is all within the data jobs database. Now going back to this diagram, you saw earlier in the course, this is how all the tables are related. We'll have a separate lesson on how to actually read this diagram, but the main thing to understand here is that this job postings fact table is our main fact table. And then these other three tables on skills and company provide skill and company information
and they are a dimensional table. So they provide extra attributes, but the core of the information's in our fact table. So for the next few lessons, we're gonna be spending the majority of time in that job postings fact table. Once we get some basic SQL down, we'll get into how these actually relate, how to actually join them, what the heck this PK and FK actually mean. So let's actually inspect this data. So I'm going into job postings fact, selecting these ellipses here and then go into query in current notebook. Now some other things to note with this, right? We have up in the right-hand corner, it tells us which database we are connected to. That first one up here was connected to my DB, but that's okay. It's an attached database. It doesn't really matter which database we were to attach it 'cause it wasn't there yet. Anyway, that's really important to understand which one we actually have right here to actually execute the query
'cause it may prevent you from executing it. Anyway, from there, it also provides underneath it those 100 different results and the different information. What I want you to do, 'cause there's no practice problems for this lesson, what I want you to do from here is just spend some time inspecting this table, understanding the data set itself. Also feel free to use the table explorer in there to actually dive into and see these different columns and explore them further. Specifically, you could do something like dive into what's this job title short column. You could see all the different job titles available and what amount they actually take up for the data set and how many rows. So that wraps up this lesson. You should have signed up for mother duck, got into the UI and attached that data set. In the next lesson, we're gonna be diving deeper into understanding the basics of SQL syntax. So you can actually understand these SQL queries
that we just ran here. With that, see you in the next one. Going to this lesson on basic keywords. By the end of this, you should be able to, well, understand the basics, but be able to read basically any SQL statement from here on out because a lot of the keywords that we're gonna be covering in this are used time and time again in SQL queries. Real quick plug before we get into it and that is to my course notes that you get in the supporter resources. Yeah, I'm first of all ready.
They actually go through and describe everything that we're gonna be doing in an associated lesson like this one and then break down the lesson step by step with even more detail. Anyway, I digress, let's get into it. And the first keyword or keywords we're gonna be covering are select and from. And this is how you actually read this. Select identifies the columns or data from a database and then the from statement or from keyword identifies the tables we are connecting to.
Now, the asterisk in this case is a special command that says, hey, we wanna select all the columns, everything. So in the case of our job postings fact table, we could do select star to select all of this from job postings fact and showing this visually. We guys do this to get the results. Let's actually do it for real. So inside of mother duck, I'm gonna go ahead and create a new notebook. I'll call this 1.2 basic keywords. I'm starting a new cell and conveniently it automatically selects our last database that we're using of data jobs. We're gonna type in select and then star from job postings fact. From there, I can press play or use these different shortcut commands to run the cell. If you're on a Mac, you can press Command Enter on Windows. I think it's Control Enter. And this outputs all the results down below it. And it even says that it returns the first 50,000 rows in nine to six milliseconds. Now, this is not all the rows of data.
Thankfully, it caps it off to sort of limit the data. But if I scroll over here on top of job posting facts, I can see that our data set has over 1.62 million rows. One quick note in the syntax, you notice I use uppercase letters here and lowercase letters here. That's pretty standard. But if you wanted to for the keywords itself, you could use actually lowercase letters. And in this case, it's gonna still return the same result. So I can also change from press Command Enter and bam, same results. I could also change the table name itself to be all caps and still get a run. But specifically for table names and stuff, it's very important that you stick with that syntax of the lowercase because many databases require it to be what it is, the same syntax. And for keywords, it's just best practice to use these as all caps. It also makes it a lot easier to read. Now, of our job posting table, let's say I wanna select specific columns,
such as job ID and job location. Well, instead of what I can do instead of using select star, I can list out the columns or column names and then still live that from of what the table is. So back inside of Mother Duck, I'm gonna put in that job ID. I'm gonna just run this real quick. You can select one column. If you wanna select multiple different columns, you would need to enter in a comma and then from there add in the next one that you wanna use of, let's say, job location. And you can see we have some hints coming up as we type something. If I know, so I do know I want job location, I'm just gonna press tab and it's gonna accept that. Anyway, gonna go ahead and here and press Command Enter. And now we're getting that job ID and job location. Now, I like this a little bit more readable. So I'm actually gonna enter job ID and job location onto the next line. And then from there, I'm going to press tab to indent each one of those over.
I can also do that with the from statement here and press tab as well. Now, this does not affect the execution of the query. I can still run this, it provides the same results. I can also do multiple different indentations on different lines, just like this. And when I press play, it's still gonna run. It doesn't really matter. This is all just for my readability and also if I make a good query, it's for my coworkers readability. Now, it's very resource-intensive to the computer itself if we were to continuously always pull all the columns from a data set. So in this case, if we wanted to just pull the top three rows, we'd need to use a keyword to limit it to that. Well, conveniently, we can use limit and limit goes at the very end of your SQL query. And you specify the number of rows that you want from this. In this case, return those three rows. So inside of our query, I'm gonna go in and put
at the very end and put a limit of, we'll just do 10, press command enter and run this and only get 10 rows returned. Anytime you're building queries on large databases, you need to be using this keyword. You can always remove it at the end after you build it and verify that it's working properly. You'll save your boss a lot of money. So going back to this diagram, where we showed the database container, its schema and the tables and the hierarchy for it, we can specify any one of these things, assuming they're in the appropriate order. So right now we have the database and then the table. Remember, we also have something like the schema itself so you could specify the schema in here as well. When we run it, run just the same. Update the other portion of the query for this. It works just fine. Now in the more advanced lessons, we'll get into when you need to put this nomenclature

Ask anything
We've read this whole study set, so questions about it get the best answers.