sql - Select data from multiple tables and grouping in mysql -


this part of assignment working on. have database named company, there 6 tables

  • employee
  • departments
  • dept_emp
  • titles
  • salaries
  • dept_manager

now have list number of engineers in each department.

i came following query:

select departments.dept_name department_name,        count(titles.title) no_of_engineers departments,      titles titles.emp_no = dept_emp.emp_no   , dept_emp.dept_no = departments.dept_no   , titles.title "% engineer %" group departments.dept_no; 

but gives me error

unknown column 'dept_emp.emp_no' in 'where clause'

but dept_emp table has column named emp_no. can see error in this? in advance

you missing join dept_emp:

select departments.dept_name department_name,        count(titles.title) no_of_engineers departments      inner join dept_emp       on(dept_emp.dept_no = departments.dept_no)      inner join titles       on(titles.emp_no = dept_emp.emp_no) titles.title "% engineer %" group departments.dept_no; 

i've corrected joins, please try avoid use of implicit join syntax(comma separated) , use proper syntax of joins.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -