1

I am stuck on the getting a result of a query like-

I need all the rows from a table except the first rows, cause i have another query for the first one only.

SELECT * FROM `about_news` WHERE `type` = 'latest' ORDER BY `news_id` DESC LIMIT 1, ?

What to put in the place ? sign to get all the results?? I think starting from 1 is correct.

BenM
  • 49,881
  • 23
  • 107
  • 158
Mysterious
  • 51
  • 7
  • Just specify a number largest enough to return all records. – BenM Oct 10 '16 at 11:22
  • You can try this: http://stackoverflow.com/questions/8509996/is-there-a-way-to-get-the-row-number-in-mysql-like-the-rownum-in-oracle – Tom Oct 10 '16 at 11:23
  • Alternatively if `news_id` is your PK, you can use a sub-query: `SELECT * FROM about_news WHERE type = 'latest' AND news_id NOT IN (SELECT news_id FROM about_news ORDER BY news_id DESC LIMIT 1) ORDER BY news_id DESC` – BenM Oct 10 '16 at 11:25
  • Yes it works for me. Thanks to everyone, I already search for the answer but didn't find... May be it is because of my knowledge. – Mysterious Oct 10 '16 at 11:29

1 Answers1

0

If you already have query for first row, than it means you already have it's ID.

SELECT * FROM `about_news` WHERE `id` != :firstRowId AND `type` = 'latest' ORDER BY `news_id`

and pass in first row ID.

Justinas
  • 34,232
  • 3
  • 56
  • 78