From the course: Advanced SQL: Logical Query Processing, Part 1

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Grouped query with Distinct

Solution: Grouped query with Distinct - SQL Tutorial

From the course: Advanced SQL: Logical Query Processing, Part 1

Start my 1-month free trial

Solution: Grouped query with Distinct

- [Instructor] Like before, I always start with a from clause and first join all the tables I think I'll need with an inner join as a starting point, alias them, add the qualification predicate and execute a quick select star, just to make sure I didn't miss anything obvious and that the query executes. Since I need to include animals that were never vaccinated, I'll change the join to a left outer and now I'll also add an order by for good measures and execute it again. I know we have animals that were not vaccinated so it's a good idea to make sure I can see some rows with no for vaccination attributes and it looks good so far. Now I can attend to the select expressions and start with the ones I already have available. From the animals table, I can get name, species, primary color and breed. And from the vaccination table, I can get vaccine. Now we can move on to the grouping. I know we need to return one row per animal…

Contents