2016-08-03 2 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의 워크 벤치를 비교하는 단지에 대한 ID의가 있었다 무시하는 것은 str_entities에서 heder을 나에게 res_companies enter image description here

을위한 테이블 헤더를 출력하는 다음 enter image description here

입니다 제공 그리고 여기 enter image description here

+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입니다.

+0

이것은 0이지만 res_companies 테이블에는 5000 개의 행이 있습니다. 그건 내 문제가 – Lauchix

+0

하지만 그들 중 누구도 귀하의 기준에 맞는'str_entities' 테이블의 행에 존재하는'id' ='entity_Id'가 없습니다 ... 당신이'res_companies'의 모든 행을 원한다면'entity_id 그들이 가지고 있니? –

+0

그 특정 회사에 주문 (str_entity.entity_type_id = 7)을 모두 갖고 싶습니다. – Lauchix