2016-08-03 10 views
-2

私のmysql出力はワークベンチに問題があります。私はtimestamp(updated)と一緒に会社(qualified_name)を取得しようとしています。 会社とタイムスタンプは異なるテーブルにあります(ヘッダーはさらに下にあります)。私はMySQL LEFT OUTER JOINが動作しません

SELECT entity_id, c.id, o.id, o.updated, 
    res_companies.qualified_name 
FROM str_entities as o 
    JOIN str_entities c 
     ON c.id = o.owner_id 
      AND c.client = "client" 
    LEFT JOIN res_companies 
     ON entity_id = c.id 
where o.status = "active" 
    AND o.entity_type_id = 7 

のMySQL Workbenchは、出力enter image description here

はここres_companies enter image description here

そして、ここでのテーブルヘッダはstr_entities enter image description here

からhederであることを私に与えを比較するためだけのidのがあった無視
+2

問題はなんですか? –

+0

entity_idはどこから来ますか?あまりにもあいまいです – Matthew

+0

私の投稿を編集しました。 – Lauchix

答えて

0

これを試してみてください。

Select count(*) from res_companies rc 
Where exists (Select * from str_entities se 
      Where id = rc.entity_id 
       and client = "client" 
       and exists (Select * from str_entities 
          Where owner_id = se.id)) 

そこにレコードがありますか? 結果がゼロ(0)の場合、指定した条件に一致するレコードがテーブルに存在しないため、最後の列(null結合)がnullになります。

+0

これは0ですが、res_companiesテーブルには5000行あります。 これは私の問題です – Lauchix

+0

あなたの条件を満たすテーブル 'str_entities'の行に存在する' id' = 'entity_Id'はありません...' res_companies'のすべての行を 'entity_id彼らは? –

+0

その選択で、すべての注文(str_entity.entity_type_id = 7)を特定の会社 – Lauchix

関連する問題