1

我在用户指南上找不到任何关于 JOIN AS 的信息,这就是我想要做的:

SELECT 
c.id
,c.name AS companyName
,con.id AS conID
,l.id AS lid

FROM
     company AS c
LEFT JOIN
     contacts AS con ON
     c.primary_contact = con.id
LEFT JOIN
     locations AS l ON
    c.id = l.cid

任何人都有一个快速的解决方案,或者将我指向指南中我似乎无法通过 AS 语句找到的部分

4

3 回答 3

0

像这样试试

SELECT 
    c.id
   ,c.name AS companyName
   ,con.id AS conID
   ,l.id AS lid

FROM
   company c
LEFT JOIN
   contacts con ON
   c.primary_contact = con.id
LEFT JOIN
   locations l ON
   c.id = l.cid

您无需提及 AS 的连接表名称,如果您在表名称之后给出名称,它将自动为您正在连接的表添加别名。

尝试在 Ci 喜欢

$this->db->select('c.id
                  ,c.name AS companyName
                  ,con.id AS conID
                  ,l.id AS lid'); 
$this->db->from('company c');        
$this->db->join('contacts con','c.primary_contact = con.id','left');
$this->db->join('locations l','c.id = l.cid','left');       
于 2013-06-06T04:44:31.700 回答
0

我不确定,但你可能想试试这个:

$this->db->select('company.id','name','contacts.id','locations.id');
$this->db->from('company');
$this->db->join('contacts','company.primary_contact = contacts.id','left');
$this->db->join('locations','contacts.id = locations.id','left');
于 2013-06-06T05:43:20.023 回答
0
$this->db->select('t1.*, t2.*')
         ->join('table2 AS t2', 't1.column = t2.column', 'left');

return $this->db->get('table1 AS t1')->result();
于 2013-06-06T15:45:21.537 回答