Re: PHP + MySQL - Load last inserts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>I have some troubles with php and mysql.  I have a normal MySQL Query 
>and this returns X > 3 rows.
>Now i want to get the last 3 inserted values. For Example i've inserted
>
>A, B, C, D, E
>
>I want to get the last inserted values, e.g. E D C (in reversed order)
>
>So how to do this? I already searched the web and the whole php.net site 
>but i don't see any workaround.

I guess you have a numeric primary key with auto_increment activated.
Then just order your select by that primary key in descending order and limit the output to 3.

For instance:

SELECT *
FROM table
ORDER BY primary_key DESC
LIMIT 0, 3;

Greetins from Germany

Marc

--
Sync and share your files over the web for free
http://bithub.net

My Twitter feed
http://www.twitter.com/MarcSteinert



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux