imekul Posted July 23, 2008 Share Posted July 23, 2008 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! Quote Link to comment Share on other sites More sharing options...
accident Posted July 23, 2008 Share Posted July 23, 2008 SELECT * FROM blog ORDER BY sticky DESC, entrynumber DESC LIMIT 50 Quote Link to comment Share on other sites More sharing options...
imekul Posted July 23, 2008 Author Share Posted July 23, 2008 That was easy! Thank you very much, accident! Quote Link to comment 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.