From the course: Learning SQL Programming

Unlock the full course today

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

Solution: Practice with JOINs

Solution: Practice with JOINs - SQL Tutorial

From the course: Learning SQL Programming

Start my 1-month free trial

Solution: Practice with JOINs

(upbeat music) - [Instructor] Here's how I solved the first challenge where we needed to find out how many hats need to go to each state. I wrote SELECT states.state_name COUNT people.shirt_or_hat FROM states JOIN people ON states.state_abbrev=people.state_code WHERE people.shirt_or_hat='hat' GROUP BY people.shirt_or_hat, states.state_name. And here's the result. To check this result, we can always go back to the table and do a manual count. Arkansas, for example, has four hats. If I click browse data, make sure I'm on the people table and all sort the data by state code. Here are the participants from Arkansas and I can see one, two, three, four hats. Looks like my query works the way I expect. And to find out how many members of each team there are in each of the census divisions, here's what I wrote. SELECT states.division, people.team, COUNT people.team FROM states JOIN people ON…

Contents