Learn Basic SQL in 10 Minutes



hey check out the fancy logo welcome to statistical programming dinette where we help you learn all the ways that programming can help you quantify qualify and generally predict your world today we're going to be learning basic commands from sequel which is the language of relational databases that if you plan to analyze data for a modern business there's a 95% chance the data is housed in a data warehouse and sooner or later you'll have to retrieve it yourself but sequel commands are not quite like any other kind of programming so if you are new to it there's nothing like a good visual representation of what each command your command is doing let's get into that now this video in a lot of learning material I plan to create is based on a visual approach when you visualize something you're forced to create that thing using your imagination and doing so will really tell you where you have a solid understanding and where you do not furthermore as you create a visual model of what you're working with you give yourself a clear reference point to relate to as you build more complex understanding and that's going to work very well as we start with database basics a database is a bunch of rows stacked on top of each other or maybe it's a bunch of columns that are smashed together side by side no one's quite sure but what we can all agree on is that rows and columns each make up a table now tables have some interesting properties such as their primary key which defines the granularity of the table and also allows them to join two other tables and speaking of the other tables a collection of them is known as a database and this is the thing that we can query with our sequel scripts since this is statistical programming net what we're interested in is the ability to use the data in some environment outside of sequel such as a programming language like Python or even a simple extra light sheet a cool feature of sequel commands is that they're very phonetic that they describe a function well so when I think of select which is our first command that we're going to learn I picture them taking items off a cart and place it into my shopping basket so let's look at how the select statement is written the term select goes first and is always eventually followed by from as in what table or tables should we pull from next we need to tell which columns we want to select in this video I'm just going to refer to columns by their color as if that were their name and the names in our example will be blue column orange column or green column these will always follow the word selects and always will be followed by the word from oh and don't forget to separate with a comma except the last one otherwise you will get an error next we'll put the table name or names after the word from and we'll finally have everything we need to complete the most basic select statement so it'd be very limiting if we could only grab whole columns from our tables as many databases contain hundreds of thousands even millions of rows the where statement acts as a way to filter out rows you don't want to include in your results for this example I'm using the dark colored lines within the cells to resent representative values notice the two red values in our bloom column suppose this column refers to order status for some ecommerce site and dark red values represent cancellations of some kind and we want them excluded from our select statement to do so we're going to add where blue column does not equal dark red aside from does not equal just as an aside we could also use a greater than a less to move n value an equal sign in or not in to filter out a group and or a few others but we're going to keep things simple with this does not equal save them so getting back to it it's important to understand that this has the effect of filtering the results before they are accessed in our query so our red records here are going to basically be filtered out before the rest of the data is selected and this is what this is going to look like kind of visually the red records disappear and our select statement our data is now ready to be used in our select statement so the where statement always goes at the bottom of the query and our final statement will look like this beautiful but wait I thought sequel is all about query in databases not just tables it is that's where joins come in adding the join clause to your select statement allows you to combine tables based on some common key in our select statement that join clause appears after the word from but before aware statement which we don't have in this example we select from our first table and then add the word join followed by the second table we wish to pull from like so then to complete the clause we identify the columns from each table on which they'll join side note they don't have to be the exact same name they just have to contain values that will match up with each other the joint works by matching exact values from one column to the other notice here that our red and green values are not physically matched on the same rows the join will shift each row based on the value it's joined column matches up to watch the table on the right closely as the entire rows move to match the blue columns together finally once the join columns are aligned the two tables are merged together and then just like in the where statement this merge allows the Select process to begin so while the joy we just learned merges tables side-by-side the union matches tables or a single column top to bottom a basic example is a union statement sitting between two select statements the union says that after the blue and yellow columns are selected from Table one they should be placed on top of the blue and yellow columns of Table two notice we have the exact same column names the union can only occur on tables with the exact same column names and where the columns being Union have the same data type so in the past I have emphasized that a filter or a joint happens before the Select statement in the case of this query the Select statements go first followed by the Union which results in the two tables converging via their columns the last sequel command that I'm going to go over is the group by clause the group by is necessary in the Select statement when there is a mathematical operation being performed over one or more of the columns but there also exists a column with no operation being done to it the group I sits at the end of the query followed by the column or columns that are not part of the mathematical operation in this case the blue column in our example this query performs the sum function over the green column with respect to the unique values in the blue column you'll notice the values in the green column that correspond to the duplicate dark red and dark green values in the blue column will be combined in total together for our final result this has been a basic walkthrough of the commands an analyst is most likely to use while query from a database although each command represents a simple concept there are derivation of each that can become quite complex writing expert level sequel queries can devolve many combinations of the commands discussed and can approach the skill level of actually an art form but it's all based on the fundamental understanding of the basic concepts later videos will dive into each of these commands in more details and also some more advanced sequel strategies until then Godspeed and thanks so much for watching

25 thoughts on “Learn Basic SQL in 10 Minutes”

  1. I think this was an awesome brief overview. I'll know more after further research, but great start right here. Thanks

  2. James Vance!! Vance Refrigeration!!

    I'm sure you've never heard that one before. In all seriousness, thanks for the video. Very informative!

  3. I started a new job today and part of their requirements are that I learn basic sql queries, this video will help me out so many thanks.

  4. Exam is in about 9 hours, so that's ~540min, that means that I can watch this video 54 times but if I speed it up to 1.5, I can watch it about 80 times… yeah, I got this.

  5. James, i am new to IT field i have no experience at all, can you give me a guidance as to how and where i should start, as i am planning to get certified in DBA.
    Thanks in advance!

  6. I'm a data analyst just learning SQL if I want to practice this at home what do I need to download? How and where do I access the platform to enter the SQL code. Also with the tables how to I name them, I assume it's easy if they are in Excel. First off?

  7. Group By looks for same values in Blue column right? I wish you used names or other ways to indicate the blue column, for example maybe it was warehouse numbers warehouse 1, warehouse 2, warehouse 3, warehouse 1, and you somehow had two of these (maybe because you used Union) so now you are combining two warehouse 1 stock quantity reported by different workers. I love your simple explanation but we to explain to people how SQL or basic database can be utilized on day to day operation. Most people have no clue how to utilize sql. They think it's complicated and requires a lot of investment, while it's just a fancy excel.

Leave a Reply

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