Skip to content
Advertisement

Mysql count the different id’s of the foreign key

I have the following tables:

jobs:

employments:

applications:

application_states

I want to create a query that counts the different application_state_id’s

This is the query that i have at the moment:

I thought i could create 2 joins and set the application_state_id, but all that does is count records double. What do i need to change in this query? I hope someone can help me.

Advertisement

Answer

You did not provide sample data, but as I see from your code
you are joining the table applications twice,
so by the 1st to get the total number of candidates
and by the 2nd to get the total number of hired candidates.
I think you can drop the 2nd join and do conditional counting to get the total number of hired candidates.
Also:
the select statement must include the columns that you group by and any aggregated columns
and I don’t see why you need to join to the application_states table.
Try this:

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