Jump to content

SELECT * FROM table ORDER BY id Except Last Entry ?


canalcasting

Recommended Posts

Hello everyone.

I just know a little about this and I just can't get further on this issue.

I am trying to display all data from mysql except the last one ?

is it possible ?

 

Not sure if I explain it clearly but for example, I have 10 entries in a table... If I add one, then it would be 11 total. The Query would only show the id from 1 to 10.... and vice versa... if there is 45 entry, then the query would show id 1 to 44.

 

Every time I would add one entry, the query would only show all Except the last one entered..

 

Someone told me about this addtion :  where id>max(`id`) order by id  but I only get syntax error ....

 

this is what I have  now : "SELECT * FROM dailynews ORDER BY id DESC where id>max(`id`) "

 

I have looked everywhere but I just don't get it....

Would appreciate any advice , help.....

Thanks so much

Not sure if the syntax is right on the second query, but this is how I would do it... should give you an idea...

 

<?php
$query = "SELECT `id` FROM `dailynews`";
$result = mysql_query($query);
$rows = mysql_num_rows($result);

$rows2 = $rows - 1;

$query2 = "SELECT * from `dailynews` ORDER BY `id` DESC LIMIT 1, $rows2";
// ...
?>

I had similar type of problem like yours and had got this code (yeah... from here  ;))

SELECT * FROM `dailynews` WHERE id < (SELECT MAX(id) FROM dailynews);

 

This will work definitely but a mod here said it is not reliable  ??? confused till now

http://www.phpfreaks.com/forums/index.php/topic,165518.msg728414.html#msg728414

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.