2016-08-03 92 views
-2

我在工作台上的mysql输出有问题。我试图让公司(qualified_name)和时间戳(更新)一起。 公司和时间戳记在不同的表格中(标题进一步向下)。忽略ID的当时只有我比较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工作台给我,输出enter image description here

这里是res_companies enter image description here

表头下面是来自str_entities的海德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),则最后一列(来自左连接)为空,因为表中没有与您指定的条件匹配的记录。

+0

它是0,但在res_companies表中是5000行。 这是我的问题 – Lauchix

+0

但他们没有一个'id' ='entity_Id',它存在于表str_entities中的行中,符合您的条件...您是否想要'res_companies'中的所有行,无论entity_id “他们有? –

+0

在那个选择我想要所有订单(str_entity.entity_type_id = 7)到他们的具体公司 – Lauchix