0

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 version: 5.0

Table structure

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

I tried this

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?

ellak
  • 2,531
  • 20
  • 26
osanjur
  • 1
  • 1

2 Answers2

1

The LIMIT cause allows you to set an offset.

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

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

Arnold Daniels
  • 16,516
  • 4
  • 53
  • 82
fionbio
  • 3,368
  • 2
  • 23
  • 38
0

I would tried the following:

SELECT *
  FROM mytable
 ORDER BY news_date DESC, news_id DESC
 LIMIT 18446744073709551615 OFFSET 3;
vyegorov
  • 21,787
  • 7
  • 59
  • 73