Difference between two codes

I was having some trouble understanding why two codes when executed had two difference answers, but both are the same just written differently?

My answer

SELECT project_name

FROM projects

INNER JOIN employees ON projects.project_id = employees.employee_id

WHERE personality = "ENFJ";

Answer under the hint section

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);

But when going into each code … this section:

SELECT personality
   FROM employees
   GROUP BY personality
   ORDER BY COUNT(personality) DESC
   LIMIT 1

Is the same as the result of the first code which is “ENFJ”? Hope someone can help me get a better understanding. Thank you!

Hello @marcocon ,

Is this a lesson in one of the Codecademy courses? If so, please include the link.

If not, I’ll still try to answer your question.

Your first SELECT statement will only return employees with personality = "ENFJ".

The SELECT above is going to return the personality that most employees have. Just run the statement above and see what it returns. Sometimes working with data and breaking down each select statement helps.

You could also try running to view the data:

SELECT personality, count(*)
FROM employees
GROUP BY personality
1 Like