Select first_name as Служащий from Customers Where first_name='JOHN' Select first_name as Коллеги, department_id from Employee Where department_id=(Select department_id from Employee Where first_name='JOHN' ) AND first_name<>(Select first_name from Employee Where first_name='JOHN' ) 

UNION is not suitable. I need the table to look like: Employee, Colleagues, Department ID

1 answer 1

 SELECT t1.first_name, t2.department_id, GROUP_CONCAT(t3.first_name) FROM Customers t1, Employee t2, Customers t3 WHERE /* t1.first_name='JOHN' AND */ t1.department_id = t2.department_id AND t2.department_id = t3.department_id AND t1.first_name != t3.first_name GROUP BY t1.first_name 

If you need only for one JOHN-a - uncomment the condition, but remove the grouping.

  • there is a sql-server in which there is no group_concat - Mike
  • Well link through XML, business ... - Akina