选择除最近的四个以外的所有行 [英] select all rows except the four most recent

查看:65
本文介绍了选择除最近的四个以外的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表(新闻),我尝试选择除最近的四行之外的所有行.该表具有一个字段news_date(日期格式)和news_id(自动增量).结果应该是desc.

I have a table (news), I try to select all rows except the four most recent. The table have a field news_date (date format) and news_id (autoincremet). The result should be desc.

MySQL版本: 5.0

MySQL version: 5.0

表结构

news_id       (tinyint)  
news_title    (text)  
news_date     (date)

我尝试过

Select *
FROM news AS n
   JOIN
       ( SELECT news_id 
         FROM news 
         ORDER BY news_id       
           LIMIT 1 OFFSET 4
       ) AS lim
     ON n.news_id < lim.news_id ;

有人可以帮助我进行此查询吗?

Can anyone help me with this query?

推荐答案

LIMIT原因允许您设置偏移量.

The LIMIT cause allows you to set an offset.

SELECT * FROM mytable ORDER BY news_date LIMIT 3,18446744073709551615;

初始行的偏移量为0(而不是1).有关更多信息,请阅读MySQL手册中的"SELECT语法" .

The offset of the initial row is 0 (not 1). For more info read 'SELECT Syntax' in the MySQL manual.

这篇关于选择除最近的四个以外的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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