0

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;
wewe
  • 193
  • 1
  • 5
  • 17

4 Answers4

0

Try this

 $this->db->join('t2', 't1.x = t2.c', 'left');
Vaibs_Cool
  • 6,126
  • 5
  • 28
  • 61
  • I think, `OP` wants to join/concat two columns in one from same table.row, not two tables but I could be wrong too. – The Alpha Sep 30 '13 at 07:46
  • 1
    Maybe you should provide an explanation to this code snippet. What was wrong with original code? What has changed? Why it should work? – default locale Sep 30 '13 at 07:51
0

Your question is not clear but to join two columns in one you may use CONCAT function in your select statement like this

$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. Also, for group concat check this answer.

Community
  • 1
  • 1
The Alpha
  • 143,660
  • 29
  • 287
  • 307
0

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

B--rian
  • 5,578
  • 10
  • 38
  • 89
0

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();
B--rian
  • 5,578
  • 10
  • 38
  • 89
  • Welcome to SO! Please edit your question and add a bit of explanation/ context, see https://stackoverflow.com/help/how-to-answer for more guidance. – B--rian Aug 16 '19 at 08:12