problem with method "from" of db_active_record. Apparently add a ` when using one select query as argument. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: problem with method "from" of db_active_record. Apparently add a ` when using one select query as argument. (/showthread.php?tid=61206) |
problem with method "from" of db_active_record. Apparently add a ` when using one select query as argument. - El Forum - 10-16-2014 [eluser]Unknown[/eluser] Code: $this->db->select(array('user_id','MAX(date) as date')); with a var_dump($where_clause), I get: Code: (SELECT `user_id`, MAX(date) as date FROM (`routine`) WHERE `grade` is not null AND datediff(curdate(), date ) >= 0 AND `user_id` IN (1, 2, 3) GROUP BY `user_id`) AS sq which is good. But when I try to nest this query: Code: $this->db->select('avg(r.grade) as average'); I get this: Code: SELECT avg(r.grade) as average FROM ((SELECT `user_id`, MAX(date) as date FROM (`routine`) WHERE `grade` is not null AND datediff(curdate(), `date` ) >= 0 AND `user_id` IN (1, `2`, `3)` GROUP BY `user_id`) as sq) JOIN `routine` r ON `r`.`user_id` = `sq`.`user_id` AND r.date = sq.date |