1 00:00:00,180 --> 00:00:00,870 All right. 2 00:00:00,870 --> 00:00:03,780 I mentioned I wanted to get us to writing some code as soon as possible. 3 00:00:03,780 --> 00:00:05,730 So that's what we're going to do in this video. 4 00:00:05,760 --> 00:00:10,110 Obviously, it's super early on in the course, so don't get your hopes up for doing anything crazy. 5 00:00:10,110 --> 00:00:10,920 Impressive. 6 00:00:11,280 --> 00:00:12,510 It's going to be pretty basic. 7 00:00:12,510 --> 00:00:17,280 But the idea is that I just want to introduce you to writing some SQL, show you what it's like. 8 00:00:17,310 --> 00:00:21,480 So the first thing you'll need to do is click on this link if you want to open the slides. 9 00:00:21,480 --> 00:00:27,570 I've included them with this lecture or I've included the link itself as a resource with this lecture. 10 00:00:27,570 --> 00:00:33,390 So however you would like to get there, go to this link which takes us to this page right here. 11 00:00:33,390 --> 00:00:38,820 This is the Try SQL editor and I'm going to make my screen a little bit bigger just so that you can 12 00:00:38,820 --> 00:00:39,360 see it. 13 00:00:39,360 --> 00:00:39,990 Here we go. 14 00:00:39,990 --> 00:00:42,420 And I'll start by just deleting what's already in there. 15 00:00:42,750 --> 00:00:44,580 So you might be wondering what is this place? 16 00:00:44,580 --> 00:00:45,780 That's a good question. 17 00:00:45,780 --> 00:00:48,840 It's an interactive, browser based SQL environment. 18 00:00:48,840 --> 00:00:53,970 And what that really means is that think of it as your own personal SQL sandbox in the browser, where 19 00:00:53,970 --> 00:00:55,980 you can go try some things out and play around. 20 00:00:55,980 --> 00:00:57,720 It's purely for educational purposes. 21 00:00:57,720 --> 00:01:02,280 So this is not what you would be doing if you were actually working with a real production database. 22 00:01:02,280 --> 00:01:07,740 But what it lets you do is type some SQL queries and run them by clicking this run SQL button and you'll 23 00:01:07,740 --> 00:01:08,550 get a result. 24 00:01:08,550 --> 00:01:11,610 And that's fundamentally the process of working with SQL. 25 00:01:11,640 --> 00:01:14,790 You type something and then you run it and then you get something back. 26 00:01:14,880 --> 00:01:20,250 Oh, and before we go any further, I should point out that we're talking about SQL here, not my SQL 27 00:01:20,250 --> 00:01:20,670 yet. 28 00:01:20,670 --> 00:01:25,200 And if you're confused about that distinction, totally normal question to have, wait until the next 29 00:01:25,200 --> 00:01:27,720 section when I go into detail about the differences. 30 00:01:27,720 --> 00:01:30,180 But for now, I'd like you to try running some code. 31 00:01:30,180 --> 00:01:35,340 So here's the first line of SQL that we can try running select star from customers. 32 00:01:35,340 --> 00:01:40,770 So you can either type this or copy it from the slides or from the included code file after this lecture. 33 00:01:40,770 --> 00:01:42,780 So I'll just copy it from the slides here. 34 00:01:43,690 --> 00:01:47,410 And then back in the editor, I'll paste it in and click Run. 35 00:01:47,710 --> 00:01:51,220 So the first thing you'll notice is that we get a bunch of data back. 36 00:01:51,220 --> 00:01:55,360 So I'm not going to go into the details of the syntax and what all of this means for every command we 37 00:01:55,360 --> 00:01:55,720 run. 38 00:01:55,720 --> 00:01:59,230 It's really more about just giving you an experience of running commands. 39 00:01:59,230 --> 00:02:04,180 The rest of the course talks about the details and the syntax, but what this does is it gives us all 40 00:02:04,180 --> 00:02:07,390 of the data about customers in this database. 41 00:02:07,810 --> 00:02:13,930 So you can see we've got 91 customers and every customer here has a name. 42 00:02:13,930 --> 00:02:16,510 So these are stores or restaurants. 43 00:02:16,510 --> 00:02:22,210 There's the contact at the restaurant or at the business, the address, the city, the postal code 44 00:02:22,210 --> 00:02:23,260 and the country. 45 00:02:24,280 --> 00:02:26,890 So that's all I'll say about that select start from customers. 46 00:02:26,890 --> 00:02:30,850 That gives us all of our customers data that are in the database right now. 47 00:02:30,940 --> 00:02:32,500 So here's another thing we could try. 48 00:02:32,500 --> 00:02:35,650 It's very similar select star from orders. 49 00:02:36,100 --> 00:02:42,990 So we'll just copy that and back here and the editor, I'll paste it in and click Run SQL, Run SQL. 50 00:02:43,330 --> 00:02:48,280 Same thing happens, but this time we get all of our data printed out for our orders. 51 00:02:48,670 --> 00:02:51,490 So you might be wondering where is this data coming from in the first place? 52 00:02:51,490 --> 00:02:52,510 Very good question. 53 00:02:52,660 --> 00:02:54,520 It's preprogrammed in here. 54 00:02:54,520 --> 00:02:58,840 So every time you open this in your browser, you have this pre loaded data set that you can work with. 55 00:02:58,960 --> 00:03:04,150 And just by taking a quick look at our order data, you can see we have things that can order ID, a 56 00:03:04,150 --> 00:03:10,060 customer ID, an employee ID and order date and a shipper ID, but there's really not much descriptive 57 00:03:10,060 --> 00:03:12,940 information here, and that's actually why I chose this table. 58 00:03:12,940 --> 00:03:18,100 I wanted to make the point that a lot of the data you'll be working with on its own, or like a snapshot 59 00:03:18,100 --> 00:03:20,080 like this, isn't very meaningful. 60 00:03:20,080 --> 00:03:23,200 What we actually want to do is start combining it with other tables. 61 00:03:23,200 --> 00:03:27,070 So we're not going to do that now, but that's what we're building up towards the end of the course 62 00:03:27,070 --> 00:03:32,290 is how do I combine customers with orders and products and shippers to get some meaningful answers out 63 00:03:32,290 --> 00:03:33,010 of my data? 64 00:03:33,100 --> 00:03:37,840 So here's another thing we can do very similar to what we've done already, but there's a little bit 65 00:03:37,840 --> 00:03:38,350 extra. 66 00:03:38,350 --> 00:03:45,850 So select start from products order by price descending DSC and if I paste that in here and click Run, 67 00:03:46,180 --> 00:03:49,390 what I get now are all of the products in my database. 68 00:03:49,390 --> 00:03:56,170 So they have a product ID, a name, a supplier ID, category ID, a unit and then a price. 69 00:03:56,170 --> 00:04:01,090 And they're currently sorted by most expensive down to the cheapest all the way at the end. 70 00:04:01,090 --> 00:04:05,170 So I won't force you to listen to me trying to pronounce some of these, but these are our products 71 00:04:05,170 --> 00:04:07,000 and they're currently sorted by price. 72 00:04:07,000 --> 00:04:11,170 So just a simple modification to the query yields radically different results. 73 00:04:11,170 --> 00:04:15,400 And if we just get rid of that order by price, we get the same data back. 74 00:04:15,400 --> 00:04:18,640 But now it's ordered by product ID rather than the price. 75 00:04:19,630 --> 00:04:23,470 And stepping up in complexity a little bit here, here's another query. 76 00:04:23,470 --> 00:04:28,390 This one significantly longer, and this one actually involves two different entities. 77 00:04:28,390 --> 00:04:30,940 So we saw customers, we saw orders separately. 78 00:04:30,940 --> 00:04:38,500 If you try copying this and pasting it in and you click run, what we actually get here is a list of 79 00:04:38,500 --> 00:04:43,810 records for a customer and then the number of orders a given customer has placed. 80 00:04:44,170 --> 00:04:46,960 So remember, this data is stored in two separate places. 81 00:04:46,960 --> 00:04:52,210 We had the customer's data that had nothing to do with orders, and then we had the orders data and 82 00:04:52,210 --> 00:04:57,250 all that it contained was customer ID and then we've combined them with this query. 83 00:04:57,370 --> 00:04:59,410 So do not focus on the syntax. 84 00:04:59,410 --> 00:05:00,490 Don't panic about that. 85 00:05:00,520 --> 00:05:01,930 Of course we'll get there. 86 00:05:01,930 --> 00:05:03,940 We'll talk a lot more about how to structure queries. 87 00:05:03,940 --> 00:05:07,570 I mean, most of this course is about structuring complex queries. 88 00:05:07,720 --> 00:05:10,600 In fact, here's a quick preview of some of the things we'll be doing. 89 00:05:10,600 --> 00:05:13,840 So here's an example of a slightly more complicated query. 90 00:05:13,840 --> 00:05:16,720 This time we're working with photos and images. 91 00:05:16,960 --> 00:05:22,120 We're working with users and likes and putting them all together to get some information out. 92 00:05:22,900 --> 00:05:28,870 And here's another one a little bit crazier where we're working with ratings or reviews and TV shows 93 00:05:28,870 --> 00:05:29,860 and reviewers. 94 00:05:29,860 --> 00:05:36,160 So think of like a Netflix or iTunes where you could rent or watch a TV show and then rate it from 1 95 00:05:36,160 --> 00:05:39,880 to 10 or 0 to 5 or whatever the rating scale is here. 96 00:05:39,880 --> 00:05:44,410 We're working with that data to figure out who our power users are, who are the most active users, 97 00:05:44,410 --> 00:05:46,330 who are reviewing the most things. 98 00:05:46,330 --> 00:05:50,110 So we'll be building up to these sort of queries, and by the end of the course you should be able to 99 00:05:50,110 --> 00:05:52,450 make sense of this and do a lot more, by the way. 100 00:05:52,990 --> 00:05:54,550 So that was a taste of SQL. 101 00:05:54,580 --> 00:05:56,140 Hopefully it didn't taste too bad. 102 00:05:56,140 --> 00:06:01,420 So in the next section we'll dive into the nitty gritty of what SQL is and how it compares to my SQL. 103 00:06:01,420 --> 00:06:05,620 We'll get everything installed, and then finally we'll have our first set of exercises.