开发者

how can i select max(id) using the Criteria object?

i have this code:

static public function getLastNewMessage($profile_id)
{
    $c = n开发者_开发百科ew Criteria();
    $subSelect = "select max(rc_message_box_table.id), rc_message_box_table.profile_id_to, rc_message_box_table.profile_id_from NOT IN ( SELECT rc_blocklist_table.profile_id_block   FROM  rc_blocklist_table  WHERE  profile_id = $profile_id  ) and rc_message_box_table.profile_id_to=$profile_id and opened_once = 0";
    $c->add(self::PROFILE_ID_TO, $subSelect, Criteria::CUSTOM);
    return self::doSelect($c);
    //SELECT MAX(auto-increment field), * FROM `table` 
}

the above is not working cos i get an error:

[wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' rc_message_box_table.profile_id_to, rc_message_box_table.profile_id_from NOT IN' at line 1]

how can i get the very last record with MAX(auto-increment field) using the criteria object or is there another way? please help? thanks


The error is because

NOT IN 
( SELECT rc_blocklist_table.profile_id_block   
FROM  rc_blocklist_table  
WHERE  profile_id = $profile_id  ) 
and rc_message_box_table.profile_id_to=$profile_id 
and opened_once = 0;

is not the name of a table. From which actual table (or subquery) are you trying to select?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜