Week 2: Join Tables

 One example of a query that joins tables not using keys would be the example query in the Left Join Video.

We wanted to find the name, id, department, of an instructor with the number of courses they have taught.

SELECT inst.id, inst.name, inst.dept_name, (t.course_id) 

FROM instructor inst LEFT JOIN teaches t on inst.id = t.id

GROUP BY inst.id

ORDER BY inst.id


I'm finding SQL quite fun to learn. I do have trouble, for example, if one of the columns needs to be a department name, I will sometimes choose "dept_name" from the wrong table. It takes me after I run the query a few times to realize that I should have chosen something different.

Comments

Popular Posts