1 00:00:00,430 --> 00:00:03,670 What happens when you want to use more than one condition? 2 00:00:03,670 --> 00:00:08,335 Depending on what question you want to ask, you can use either the AND 3 00:00:08,335 --> 00:00:10,192 keyword or the OR keyword. 4 00:00:10,192 --> 00:00:14,020 Let's look at a general example first with one condition. 5 00:00:14,020 --> 00:00:17,890 To add a second condition you add the appropriate keyword, 6 00:00:17,890 --> 00:00:19,110 then the next condition. 7 00:00:21,130 --> 00:00:24,240 Let's ask a question that includes two conditions. 8 00:00:24,240 --> 00:00:30,259 What books in our library were authored by J.K. Rowling before the year 2000? 9 00:00:30,259 --> 00:00:33,580 Let's remind ourselves of the table's structure. 10 00:00:33,580 --> 00:00:37,988 We want to select the title, and then we want to compare the author and 11 00:00:37,988 --> 00:00:40,125 the first_published columns. 12 00:00:40,125 --> 00:00:46,872 So, SELECT title FROM books 13 00:00:46,872 --> 00:00:52,780 WHERE author = "J.K. 14 00:00:52,780 --> 00:00:56,764 Rowling" AND 15 00:00:56,764 --> 00:01:06,065 first_published < 2000. 16 00:01:09,214 --> 00:01:14,610 Using the AND keyword means that the row has to satisfy both conditions. 17 00:01:14,610 --> 00:01:20,010 If I were to swap it out with an OR, it will retrieve books by J.K. 18 00:01:20,010 --> 00:01:24,345 Rowling OR books first published before 2000. 19 00:01:24,345 --> 00:01:29,108 As you can see, using the wrong keyword when combining conditions can 20 00:01:29,108 --> 00:01:31,740 present very different results. 21 00:01:31,740 --> 00:01:33,990 Let's ask another question. 22 00:01:33,990 --> 00:01:39,450 What books do we have in the library authored by Ernest Klein or Andy Weir? 23 00:01:39,450 --> 00:01:41,130 Let's select author this time too. 24 00:01:43,675 --> 00:01:50,713 WHERE author = "Ernest Cline" OR 25 00:01:50,713 --> 00:01:55,883 author = "Andy Weir". 26 00:02:04,127 --> 00:02:10,970 We use OR rather than AND because the AND tests if every condition is satisfied. 27 00:02:10,970 --> 00:02:14,158 Since the author cannot be both, Ernest Cline or 28 00:02:14,158 --> 00:02:18,590 Andy Weir at the same time, no results will come back. 29 00:02:18,590 --> 00:02:21,670 If we use OR we don't mind which condition is true. 30 00:02:21,670 --> 00:02:26,390 As long as one of the conditions is true, the row will be returned. 31 00:02:26,390 --> 00:02:32,663 To recap, the AND and OR keywords can be used to chain conditions together. 32 00:02:32,663 --> 00:02:36,495 With the AND keyword all conditions need to be met. 33 00:02:36,495 --> 00:02:40,510 With the OR keyword, only one condition needs to be met. 34 00:02:40,510 --> 00:02:46,650 Combining the AND and OR keywords with multiple conditions can get complex. 35 00:02:46,650 --> 00:02:50,710 I'll include some examples and details in the teacher's notes for you to refer to.