Jump to content

[SOLVED] Adding a sticky to a blog: Ordering where sticky = 1, then ordering by ID


imekul

Recommended Posts

I have a blog that displays the entries with a pretty simple query:

 

SELECT * FROM blog ORDER BY entrynumber DESC LIMIT 50

 

This works fine, and it sorts by the entry number, and thus, is in chronological order (latest post is shown first).  I'm wanting to add a sticky / announcement switch to each entry that will put that entry on top of all of the other ones, so it will basically stay on top, regardless of what its date or entrynumber is.

 

I'm thinking of adding a sticky field to the table, and then switching it to 1 on any post that I want stickified.  I can then access the stickies by using this:

 

SELECT * FROM blog WHERE sticky = 1

 

But I would like to essentially merge the two queries.  I'm not too familiar with SQL, but I understand that I should be able to have a query that will first select any post where sticky = 1 (and sort those by entrynumber, should there happen to be more than one sticky at a time).  After that, I would like it to simply sort the next 50 results by entrynumber.

 

Does anybody know how I can sort like this?  The idea seems pretty simple, but I'm not sure what the SQL would be.

 

Thanks!

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.