如何使用 Criteria 对象选择 max(id)?
我有这个代码:
static public function getLastNewMessage($profile_id)
{
$c = new 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`
}
上面的代码不起作用,因为我收到错误:
[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]
如何使用条件对象获取带有 MAX(自动增量字段)的最后一条记录,或者还有其他方法吗? 请帮忙? 谢谢
i have this code:
static public function getLastNewMessage($profile_id)
{
$c = new 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误是因为
不是表名。您要从哪个实际表(或子查询)中
选择
?The error is because
is not the name of a table. From which actual table (or subquery) are you trying to
select
?