Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDaniel Silva
5,353 PointsSQL returning same name for all results
I'm trying to run a query that selects the employees first name and last name and what department they are in. It's showing everyone in Customer Service when they should be others. The result I get is below:
FName LName Department
'Mary', 'Sluis', 'Customer Service'
'Huan', 'Lortz', 'Customer Service'
'Basil', 'Tramer', 'Customer Service'
Here is my query
use employees;
SELECT
employees.first_name,
employees.last_name,
departments.dept_name
FROM
employees
JOIN
dept_emp ON employees.emp_no = dept_emp.emp_no
JOIN
departments ON dept_emp.dept_no = departments.dept_no
I'm using 2 tables: employees (which has the emp_no, first_name, last_name), departments which has the dept_no, and dept_name. Lastly dept_emp table which I'm referencing which has the emp_no, and dept_no
1 Answer
Steven Parker
231,269 PointsThe query itself seems good, but to understand the issue it would be necessary to see the contents of all three tables.