php - How to write Subquery in codeigniter active record for this query -
select from_id, (select count(id) user_messages from_id=1223 , status=1) sent_unread, (select count(id) user_messages from_id=1223 , status=2) sent_read user_messages from_id=1223 group from_id
how write above select statement in codeigniter active record?
this came with:
$this->db->select('from_id, (select count(id) user_messages from_id=1223 , status=1) sent_unread, (select count(id) user_messages from_id=1223 , status=2) sent_read'); $this->db->where('from_id', $member_id); $this->db->group_by('from_id'); $this->db->from('user_messages'); $result = $this->db->get(); //echo $this->db->last_query(); return $result->row();
is right method?
try
<?php $query="from_id, (select count(id) user_messages from_id=1223 , status=1) sent_unread, (select count(id) user_messages from_id=1223 , status=2) sent_read"; $query_run=$this->db->select($query); $query_run->where('from_id', $member_id); $query_run->group_by('from_id'); $result = $query_run->get('user_messages'); //echo $this->db->last_query(); return $result->row(); ?>
Comments
Post a Comment