简体   繁体   English

将两列合为一列codeigniter

[英]Join two columns in one columns codeigniter

is this possible ? 这可能吗 ? two columns in one columns on table ? 表格中的两列合二为一?

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

Your question is not clear but to join two columns in one you may use CONCAT function in your select statement like this 您的问题尚不清楚,但要将两列合并为一个,可以在select语句中使用CONCAT函数,如下所示

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

This is just an idea how you can use concat function. 这只是一个如何使用concat函数的想法。 Also, for group concat check this answer . 另外,对于组连续检查此答案

try: 尝试:

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

This solution is described at http://www.tutorialspoint.com/mysql/mysql-concat-function.htm http://www.tutorialspoint.com/mysql/mysql-concat-function.htm中描述了该解决方案

I suggest to join two or more columns in same table: 我建议在同一张表中加入两个或多个列:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM