0

I can use some help with a query. I have two tables:

employee = {
  id,
  manager,

  data1,
}


hrm = {
 id,
 employee,

 data2,
};

The Query. I like to have all hrm records from the employees which have Tom as manager.

SELECT hrm.employee, hrm.data2 FROM hrm WHERE AND EXISTS  
(SELECT id from employee WHERE manager = 'TOM')

This gives me

Jan, data2
Piet, data2

Great! but I want more. :-) I also like to have the associated data1 column from employee.

Jan, data2, data1
Piet, data2, data1

Any help is appreciated.

4

1 回答 1

2
SELECT hrm.employee, hrm.data2, employee.data1
FROM hrm
INNER JOIN employee ON (hrm.employee = employee.id)
WHERE employee.manager == "TOM";

Will give all hrms associated with an employee with a manager "TOM". This assumes that hrm and employee are associated with the hrm.employee and employee.id fields.

于 2013-10-18T11:25:24.917 回答