Home > Software design >  Nested query in MySQL using select statement
Nested query in MySQL using select statement

Time:09-23

I am having trouble with the activity I have in MySQL.

Below are the tables of my employee database, and I want to show the dept_name column from the department table, first_name and last_name from the employee table, and the title_name from the title table.

ER diagram for employee database

The instruction is to query it using a select statement. If anyone knows how to do it, please help me :< thank you so much.

CodePudding user response:

You can use JOIN or write as below

SELECT e.first_name, e.last_name, d.dept_name, t.title_name
FROM employee e, department d, title t, emp_dept ed, emp_title et
WHERE 
e.emp_no = ed.emp_no AND ed.dept_no = d.dept_no
AND e.emp_no = et.emp_no AND et.title_no = t.title_no
  • Related