Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql select rows except first row

Tags:

select

mysql

I have issue there with select from table. I want to select all rows except for first row. So .. There is my code

SELECT * FROM table ORDER BY id DESC 

So this code select and order id's from table which give me id feedback "5>4>3>2>1". And there is issue .. How I can select and echo just 4>3>2>1 rows. So if I had rows with id's 1,2,6,8,10 , echo will be 10,8,6,2,1 and I want select to echo just 8,6,2,1.

There is my full wrong code for select.

$other = mysql_query("SELECT * FROM table ORDER BY id DESC LIMIT 1, 1");
like image 916
Nol Avatar asked Sep 02 '25 16:09

Nol


2 Answers

This should do it.

SELECT * FROM table WHERE id NOT IN (SELECT MAX(id) FROM table) ORDER BY id DESC 
like image 108
isaace Avatar answered Sep 04 '25 12:09

isaace


Try this:

SELECT *
FROM
(
    SELECT *, row_number()
    OVER (ORDER BY id DESC) row
    FROM table
)
WHERE row != 1

It gives numbers to your selected rows and takes all of them without the one with row number 1

like image 22
SeReGa Avatar answered Sep 04 '25 10:09

SeReGa