Hook
More breakout videos from this creator.
This is how you trap in SQL. Let's say we keep track of the people that visit the trap with a visit ID and a customer ID. We not going to store the names because that's fed. And that's our visits table. But let's say we also got another table called transactions where we keep track of who actually came to the trap and shop and the amount that they spent. And we wanna find out which customers came to the trap and didn't shop and how many times they did it because they might be the feds. So that means we gotta select the customer ID and we gotta use our count function to get how much times that customer ID appears in our filter table later on. This next part is like the most important cuz right now we got two tables but we need to combine them together into one so we can actually get what we're looking for. And we're going to use a left join and our left table here is gonna be our visits table. And twin, make sure you locked in right here. So in our left join, everything in our left table is gonna be there regardless. And now we have to join the transactions table and we have to tell it how we're gonna join it on the visit IDs and both tables. So we're checking do both of these tables both have this visit ID and if they do, that means that they came to shop. So even if we come across a road that's in the business table but there's no matching ID in the transactions table, we still add that row but the transaction ID for it's going to be no. I'm going to show you a quick look of what it looks like when we join these tables. And finally after we left join, we wanna go through and we want those rows where there's no transaction ID or transaction ID is null. So then we return the results and customer 30 and 96 are definitely the feds but customer 54, I don't know how I feel about him. I think he building a, I think he building a Rico case or something.