
from messages
where receiver_id='3'
group by send_id, receiver_id
order by id desc
limit 0,10
max() 效率更高,无论这个字段有没有索引例如:
select max(`id`) from table
select `id` from table order by id limit 1
楼主可以参考下列例句:列出所有年龄最大的学生资料
select * from students
where date_of_birth=
(select max date_of_birth
from students)
或者
select a.* from students a
where not exists (
select 1 from students b
where b.date _of_birth >a.date_of_birth)
第二种写法在有索引可被利用时效率很高,可作为首选,但是无索引可被利用且是大数据表的情况下效率很低,此时应避免使用。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)