Glenugie Posted October 9, 2009 Share Posted October 9, 2009 I'm looking to write a query that will select all rows but the first 3, basically because I have the first 3 rows displayed on my main page, and the rest are archived. I was hoping I wouldn't have to resort to something like this: $QueryAnnounce = mysql_query("SELECT PostedBy, AnnouncementBody, Date FROM GameAnnouncement ORDER BY TimeStamp DESC LIMIT 3,9999999999999"); Is there a way to just set the second value to the exact number of rows? And if so, would someone mind clarifying what it was? Thanks in advance, ~Glenugie~ Quote Link to comment https://forums.phpfreaks.com/topic/177105-solved-select-all-but-the-first-3-rows/ Share on other sites More sharing options...
kickstart Posted October 9, 2009 Share Posted October 9, 2009 Hi That is the recommended way to do it. If you really want to avoid that syntax then maybe something like this would do it:- $QueryAnnounce = mysql_query("SELECT a.PostedBy, b.AnnouncementBody, c.Date FROM (SELECT PostedBy, AnnouncementBody, Date FROM GameAnnouncement ORDER BY TimeStamp) a LEFT OUTER JOIN (SELECT PostedBy, AnnouncementBody, Date FROM GameAnnouncement ORDER BY TimeStamp DESC LIMIT 3) b ON a.PostedBy = b.PostedBy AND a.AnnouncementBody = b.AnnouncementBody AND a.Date = b.Date WHERE b.PostedBy IS NULL"); Basically get all records and get the first 3 records, join the results with an outer join and then only return those where the matching records (ie the ones in the first 3) are empty. Personally I would just use your original solution. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/177105-solved-select-all-but-the-first-3-rows/#findComment-933802 Share on other sites More sharing options...
Glenugie Posted October 9, 2009 Author Share Posted October 9, 2009 Allright, thanks, I guess I'll just do it my way ~Glenugie~ Quote Link to comment https://forums.phpfreaks.com/topic/177105-solved-select-all-but-the-first-3-rows/#findComment-933804 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.