选择数据库时使用AS的codeigniter

选择数据库时使用AS的codeigniter,codeigniter,Codeigniter,我在用户指南中找不到任何关于加入的信息,以下是我正在尝试做的: 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 任何人都有一个快速的解

我在用户指南中找不到任何关于加入的信息,以下是我正在尝试做的:

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语句中找不到的部分

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中提及联接表名称,如果在表名称之后给出名称,它将自动为您要联接的表别名

试词

$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');       

我对此不确定,但您可能想试试:

$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');

我不知道我会按照你将如何添加到模型页面。下面是我的模型页面的样子:`$this->db->select'c.id'$这->数据库->来自“公司为c”$这->数据库->加入'contacts','contacts.id=company.primary_contact'$query=$this->db->get;返回$query->result\u数组`很抱歉,我的评论中的代码乱七八糟,显然你不能在评论中添加代码,这看起来很愚蠢。
$this->db->select('t1.*, t2.*')
         ->join('table2 AS t2', 't1.column = t2.column', 'left');

return $this->db->get('table1 AS t1')->result();