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

Link to comment
Share on other sites

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";
// ...
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.