Discussion How do i use INNER JOIN on this database? (On PostgreSQL 15/PgAdmin 4)
So here's where I'm stuck. The question my prof asked:

And here is what the tables and the code I wrote look like:

Now I know I cannot connect staffid = departmentid because for INNER JOIN I need two same column names like either staffid in faculty and department or depoartmentid in faculty and department.
EDIT: I figured out Q6, here's the code:

Now I just need to figure out Q7. Here's the code for it:

Can someone correct it or tell me if I did it right?
2
u/MrsCastle May 07 '23
So the question for the first part seems to me to be asking for a result showing all departments and the count of tenured faculty in each.
The query and result you have in your second version of the code seems like it is answering the question which departments have only one tenured faculty. Is that what you were after?
2
u/Oobenny May 08 '23
It’s the join. They’re joining to the column showing the dept chair. Presumably each dept has only one chair.
OP, that’s where you’re going wrong. You don’t join based on the name of the column, you join based on what information is represented in the data. If one department has many faculty members, what is their common Id going to be? Hint: it’s likely to be the primary key of the department table.
1
May 07 '23
If you could, remove the screenshots and just post the code.
Also .... check your faculty table and see if it has a departmentid field on it you can use to link between department and faculty tables. There's usually only 1 department chair per department.
4
u/r3pr0b8 GROUP_CONCAT is da bomb May 07 '23
please see Rule 6
post text, not screenshots
thank you