3 つのテーブルを結合しようとしています- e、、wpl
l としての場所:name | id | workplace_id
wp としての職場:name | id
e としての従業員:name | id | location_id | coordinator
私がしたい: WORKPLACE に COORDINATOR (coordinator=1) が任意の LOCATION にある場合、その WORKPLACE のすべての LOCATION を取得する
これは機能していないようです-コーディネーター= 1を持つ職場のすべての場所を返していますが、職場の場所のいずれかにコーディネーター= 1がある場合、職場のすべての場所が必要です。
select distinct w.* 
from workplaces as w, 
    (select distinct l.* 
     from locations as l, employees as e 
     where e.location_id = l.id and e.coordinator = 1) as tmp 
where tmp.workplace_id = w.id