Jump to content

[SOLVED] Select all but the first 3 rows


Glenugie

Recommended Posts

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~

Link to comment
https://forums.phpfreaks.com/topic/177105-solved-select-all-but-the-first-3-rows/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

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