1 00:00:00,090 --> 00:00:03,180 Here's a quick solution to the delete exercise. 2 00:00:03,210 --> 00:00:06,170 First up, delete all four year old cats. 3 00:00:06,180 --> 00:00:13,110 So like I said, I like to make sure I can select those first select star from cats where age equals 4 00:00:13,110 --> 00:00:14,430 exactly four. 5 00:00:14,610 --> 00:00:17,760 And it looks like there's just one of them ages four. 6 00:00:17,790 --> 00:00:19,140 Ringo Great. 7 00:00:19,140 --> 00:00:26,520 So instead of doing a select star, I'm going to do a delete from cats where age equals four. 8 00:00:26,610 --> 00:00:28,850 And I should also get some confirmation, right? 9 00:00:28,890 --> 00:00:30,960 I see one row affected. 10 00:00:31,080 --> 00:00:33,690 That is a very it's an understatement. 11 00:00:33,690 --> 00:00:36,540 It wasn't just affected, it was removed. 12 00:00:36,540 --> 00:00:39,000 If I do a select star from cats, we'll see. 13 00:00:39,000 --> 00:00:40,980 Ringo is just gone entirely now. 14 00:00:40,980 --> 00:00:45,540 And if I tried to rerun that query from earlier, a couple of lines to go select Star from Cats where 15 00:00:45,540 --> 00:00:47,820 age is four, we get an empty set. 16 00:00:47,820 --> 00:00:49,980 We have no resulting rows. 17 00:00:50,930 --> 00:00:55,690 Next, delete the cats whose age is the same as their cat ID. 18 00:00:55,700 --> 00:00:59,750 So once again, I like to start with a select select start from cats. 19 00:01:00,940 --> 00:01:05,140 And then where age is equal to cat ID. 20 00:01:05,730 --> 00:01:13,200 We saw this when we talked about selecting with where we can do things like two different column names 21 00:01:13,200 --> 00:01:14,160 and compare them. 22 00:01:14,860 --> 00:01:16,900 Now there's only one matching cat. 23 00:01:16,900 --> 00:01:20,500 So we see Jack cat idea seven age of seven. 24 00:01:20,740 --> 00:01:22,380 Well, we're going to delete you, Cat. 25 00:01:22,390 --> 00:01:31,240 I mean, Jack, technically, also cat delete from cats where age equals cat ID If I try to run my select 26 00:01:31,240 --> 00:01:32,890 again, it's gone. 27 00:01:33,100 --> 00:01:34,510 Select star from cats. 28 00:01:34,510 --> 00:01:36,760 We're now down to four cats. 29 00:01:36,790 --> 00:01:43,570 I deleted Egg in the intro to deletion video just in case you're wondering how we went from 7 to 4. 30 00:01:44,290 --> 00:01:48,520 Well, now we're going to go from four to knockouts, delete all of them. 31 00:01:48,520 --> 00:01:50,220 And this one, simple enough. 32 00:01:50,230 --> 00:01:51,790 You just want to be careful with this. 33 00:01:52,060 --> 00:01:56,140 If I do delete from cats and nothing else, they're all gone. 34 00:01:56,230 --> 00:01:59,020 So be careful if you have data you care about. 35 00:01:59,020 --> 00:02:01,060 But we don't have anything we care about. 36 00:02:01,060 --> 00:02:02,080 I'm sorry, cats. 37 00:02:02,650 --> 00:02:05,440 We've shut down the shelter and euthanized all of you. 38 00:02:05,470 --> 00:02:06,400 Goodbye. 39 00:02:06,730 --> 00:02:08,169 Now we look at cats. 40 00:02:09,229 --> 00:02:10,310 Nothing in there. 41 00:02:10,910 --> 00:02:11,850 Och, that's it. 42 00:02:11,870 --> 00:02:14,960 Next up, we've got a much bigger exercise to put it all together.