将两列连接在一列代码点火器中


Join two columns in one columns codeigniter

这可能吗? 表上的一列中有两列?

$this->db->select('header.*,customer.*,destination.location');
$this->db->from(self::WAYBILL_HEADER_TABLE. " as header");
$this->db->join(self::CUSTOMER_TABLE." as customer","header.consignee = customer.id");
$this->db->join(self::WAYBILLDESTINATION_TABLE. " as destination","header.destination_from = destination.id",'INNER');
$this->db->join(self::WAYBILLDESTINATION_TABLE. " as destinations","header.destination_to = destinations.id",'INNER');
$this->db->where('header.waybilldate <=',$date_to);
$this->db->where('header.waybilldate >=',$date_from);
$this->db->order_by('header.waybillno','DESC');
$query = $this->db->get()->result();
return $query;

试试这个

 $this->db->join('t2', 't1.x = t2.c', 'left');

您的问题不清楚,但要将两列合二为一,您可以在 select 语句中使用 CONCAT 函数,如下所示

$this->db->select('table_name.column1, CONCAT(table_name.column2, ' ', table_name.column3) as table_name.twoInOne');

这只是如何使用concat功能的想法。另外,对于组连接,请检查此答案。

我建议在同一表中连接两列或多列:

    $this->db->select("*");
    $this->db->from("follows");
    $this->db->join('users table1','table1.user_id=follows.following_id','left');
    $this->db->join('users table2','table2.user_id=follows.follower_id','left');
    $this->db->where("table1.is_active",1);
    $this->db->where("table2.is_active",1);
    $res=$this->db->get();
    return $res->result();

尝试:

$this->db->query("SELECT CONCAT(column1,' ',column2) FROM employee_tbl");

此解决方案在 中介绍http://www.tutorialspoint.com/mysql/mysql-concat-function.htm