简体   繁体   中英

How can I ORDER the result after i've used LIMIT?

This is kind of straight forward. I want to ORDER BY date DESC Limit 4 and then I want to ORDER BY date ASC on that result, so just 4-games from the middle of the big table with ASC date order, any ideas? Just ORDER BY date ASC Limit 4 Does not work!

What I have: 在此输入图像描述

What I get: 在此输入图像描述

What I want: 在此输入图像描述

你可以使用子查询:

SELECT a.* FROM (SELECT * FROM yourtable ORDER BY date DESC Limit 4) a ORDER BY a.Date 

if you want to get the last four rows from table

select * from table  order by date desc limit 0,4

if you want to get the first four rows from table

select * from table  order by date asc limit 0,4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM