jasonc Posted April 21, 2010 Share Posted April 21, 2010 how do i select all but the last recent 10 entries from a table. SELECT * FROM `table` WHERE `user` = 'username' ORDER BY `date` Quote Link to comment https://forums.phpfreaks.com/topic/199253-select-all-entries-but-not-the-last-10-recent-entries/ Share on other sites More sharing options...
Mchl Posted April 21, 2010 Share Posted April 21, 2010 First select last 10, then remove them from resultset SELECT * FROM `table`AS t1 LEFT JOIN (SELECT ID FROM `table` WHERE `user` = 'username' ORDER BY `date` DESC LIMIT 10) AS t2 ON t1.ID = t2.ID WHERE t2.ID IS NULL AND `user` = 'username' ORDER BY `date` Quote Link to comment https://forums.phpfreaks.com/topic/199253-select-all-entries-but-not-the-last-10-recent-entries/#findComment-1045786 Share on other sites More sharing options...
F1Fan Posted April 21, 2010 Share Posted April 21, 2010 Another option (untested): SELECT * FROM `table` WHERE `user` = 'username' ORDER BY `date` LIMIT ((SELECT count(*) FROM `table` WHERE `user` = 'username') - 10) Quote Link to comment https://forums.phpfreaks.com/topic/199253-select-all-entries-but-not-the-last-10-recent-entries/#findComment-1045846 Share on other sites More sharing options...
Ken2k7 Posted April 21, 2010 Share Posted April 21, 2010 Another option (untested): SELECT * FROM `table` WHERE `user` = 'username' ORDER BY `date` LIMIT ((SELECT count(*) FROM `table` WHERE `user` = 'username') - 10) I doubt that will work. Quote Link to comment https://forums.phpfreaks.com/topic/199253-select-all-entries-but-not-the-last-10-recent-entries/#findComment-1045849 Share on other sites More sharing options...
Mchl Posted April 21, 2010 Share Posted April 21, 2010 I doubt that will work. And rightly to do so. Quote Link to comment https://forums.phpfreaks.com/topic/199253-select-all-entries-but-not-the-last-10-recent-entries/#findComment-1045868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.