VR Startup Companies Exercise 10

Hello,

I’m working on the VR startup companies exercise question #10 here.

The hint in the exercise returned the solution with this code:

SELECT project_name
FROM projects
INNER JOIN employees
ON projects.project_id = employees.current_project
WHERE personality = (
SELECT personality
FROM employees
GROUP BY personality
ORDER BY COUNT(personality) DESC
LIMIT 1);

However, I was able to return the same results with this query:

SELECT project_name
FROM projects
INNER JOIN employees
ON employees.current_project = projects.project_id
GROUP BY project_name
HAVING personality = ‘ENFJ’;

Is the suggested code inherently better? Is there any reason my solution would be inferior?

Yes, I think the suggested code is better.

In your code, you’ve hard coede ‘ENFJ’, which means the result of the query will remain the same even when there are changes in ‘employees’ table and the personality of most employees is no longer ‘ENFJ’. I think in real world it’s better not to have such hard-coded information in the code.

1 Like

That makes sense. Thank you for the feedback!