1 00:00:00,420 --> 00:00:05,750 In the previous video we used the select star from table query to retrieve all 2 00:00:05,750 --> 00:00:10,710 information in a table, but you may not want to bring back all the information. 3 00:00:10,710 --> 00:00:13,760 Often you want a smaller subset of information. 4 00:00:13,760 --> 00:00:17,110 This can be particularly helpful if you don't want to bring back sensitive 5 00:00:17,110 --> 00:00:18,120 information. 6 00:00:18,120 --> 00:00:21,250 Like the addresses or dates of birth. 7 00:00:21,250 --> 00:00:24,770 Let's take a look at some simple ways to retrieve only some 8 00:00:24,770 --> 00:00:26,970 of the information in a table. 9 00:00:26,970 --> 00:00:30,100 Let's start with all the information from the patrons table. 10 00:00:30,100 --> 00:00:31,630 And we can filter it down from there. 11 00:00:34,220 --> 00:00:39,380 The asterisk, or star, is short hand for all of the column names in the table. 12 00:00:39,380 --> 00:00:44,120 Now, what if I wanted to retrieve only the emails from our patrons table? 13 00:00:44,120 --> 00:00:48,460 We still want to select something from our patrons table. 14 00:00:48,460 --> 00:00:50,910 So our query mostly stays the same. 15 00:00:50,910 --> 00:00:54,390 All we need to do is change the asterisk, remember? 16 00:00:54,390 --> 00:00:57,290 An asterisk is shorthand for everything. 17 00:00:57,290 --> 00:01:00,110 We can replace it with the column name we want. 18 00:01:00,110 --> 00:01:01,981 In this case, it's email. 19 00:01:05,541 --> 00:01:10,160 As you can see this selects all the emails from our patrons table. 20 00:01:10,160 --> 00:01:12,160 Let's try one more. 21 00:01:12,160 --> 00:01:15,990 What if we wanted all the first names in our patrons table. 22 00:01:15,990 --> 00:01:17,770 You can probably guess what we need to do. 23 00:01:17,770 --> 00:01:22,490 You just to write the name of the first name column, first_name, 24 00:01:22,490 --> 00:01:24,970 between the select and from keywords. 25 00:01:27,801 --> 00:01:29,402 Okay, let's change that back. 26 00:01:33,302 --> 00:01:38,880 Having either all columns or a single column returned back has limited utility. 27 00:01:38,880 --> 00:01:43,340 Remember, the power of SQL is that you can retrieve any subset of information 28 00:01:43,340 --> 00:01:47,700 from a table without being destructive to the underlying data. 29 00:01:47,700 --> 00:01:50,650 Nothing is deleted, it's just presented differently. 30 00:01:52,240 --> 00:01:56,960 Let's say I wanted to send out a library newsletter talking about the new books 31 00:01:56,960 --> 00:01:58,400 available to loan. 32 00:01:58,400 --> 00:02:00,940 How do I go about retrieving both the first name and 33 00:02:00,940 --> 00:02:02,800 email address of each patron? 34 00:02:02,800 --> 00:02:03,700 In other words, 35 00:02:03,700 --> 00:02:08,360 how do I select two columns of data from the database with one query? 36 00:02:08,360 --> 00:02:11,370 SQL makes this kind of task pretty easy on us. 37 00:02:11,370 --> 00:02:13,547 I can simply separate the name for 38 00:02:13,547 --> 00:02:16,670 each column I want with a comma in the SQL query. 39 00:02:19,130 --> 00:02:23,881 The great thing is that I can change the ordering of the columns how I see fit. 40 00:02:34,121 --> 00:02:37,002 Since the recap, the area between the SELECT and 41 00:02:37,002 --> 00:02:41,160 the FROM keywords is the columns you want to get the information from. 42 00:02:42,500 --> 00:02:46,720 SELECT * FROM patrons is a lot shorter than including all of the column names. 43 00:02:46,720 --> 00:02:49,906 You're a better person than me if you can remember all the column names. 44 00:02:49,906 --> 00:02:53,560 Let's do some code challenges to solidify what we've learned here.