如何在sql中返回10个最新结果? [英] How can I return 10 of the most recent results in sql?

查看:57
本文介绍了如何在sql中返回10个最新结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很好用,并给了我最新的结果:

This works fine and gives me the most recent results back:

SELECT * FROM table ORDER BY date ASC;

但是当我限制它以将结果减少到最近的10个时,它并不能为我提供最新的结果:

But when I put a limit on it to reduce the results to just 10 of the most recent, it doesn't give me the most recent results:

SELECT * FROM table ORDER BY date ASC LIMIT 30;

我还能怎么做?

推荐答案

尝试

SELECT * FROM table ORDER BY date DESC LIMIT 10;

DESC子句首先要求提供最近日期的记录.假设您的日期字段是DATETIME样式的字段,则应该可以使用.

the DESC clause asks for records with the most recent date first. Assuming your date field is a DATETIME-style field, this should work.

这篇关于如何在sql中返回10个最新结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆