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` 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` 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) 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. 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. 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
Archived
This topic is now archived and is closed to further replies.