Skip to content
Advertisement

How to use refer to multiple id’s when using JOINs in SQL

I try to display the number of reviews which an employee provided and the number of reviews which he received. I try to do something like this, but in my output table (3) I receive incorrect data. I believe that this happens due to the wrong reference:

however, if I reference it like this:

then nr_of_reviews_receieved is correct and nr_of_reviews_posted is not, and if I change it back it’s vice versa. So, I need in one case to use one reference and in another a different one, but all in one query.

employee table

performance_reviews table

my output table

Advertisement

Answer

You have to sample the tables twice and join to the table each time for example:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement