Welcome Guest, Not a member yet? Register   Sign In
expresstion a SQL in
#1

[eluser]startbbs[/eluser]
hi, guys, I have a SQL as below:
Code:
SELECT * from
( SELECT `a`.`tid`, `a`.`title`, `a`.`cid`, `a`.`updatetime`, `b`.`uid`, `b`.`username`
FROM (`news` a) LEFT JOIN `users` b ON `b`.`uid` = `a`.`uid`
WHERE `cid` IN ('10', '9', '8', '6', '4', '11', '7', '5')
ORDER BY a.cid, `a`.`updatetime` DESC ) alias
GROUP BY a.cid

I want to express it by Active records class, anyone can convert it using the Active Record Class?
thanks!
#2

[eluser]Sudz[/eluser]
Hi,
You can try this one
Code:
$this->db->select("a.tid,a.title,a.cid,a.updatetime,b.uid,b.username");
$this->db->from('news a');
$this->db->join('users b', 'b.uid = a.uid');
$this->db->where_in('cid',array('10','9','8','6','4','11','7','5'));
$this->db->group_by(array("a.cid");
$this->db->order_by("a.cid", "desc");
$this->db->order_by("updatetime", "desc");
$query = $this->db->get();




Theme © iAndrew 2016 - Forum software by © MyBB