therealwesfoster Posted August 14, 2009 Share Posted August 14, 2009 I have a list of 15 articles. 5 of the articles are sticky (meaning they are always at the top). I'm only wanting to show 2 sticky articles (random out of the 5), and then display 8 non-sticky articles below (making a total of 10 articles on the page). Is there a way to go about doing this with just 1 sql query? For example: (NOTE: art_sticky is either 1 or 0, so ordering that column descending will always place them at the top.) SELECT * FROM articles ORDER BY art_sticky DESC LIMIT 2, art_postdate DESC LIMIT 8 See how I have two limits? Is there some way I can make that work? Thanks! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 14, 2009 Share Posted August 14, 2009 UNION Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted August 14, 2009 Author Share Posted August 14, 2009 Thanks bro, but is there any other method? The query is huge and is built in parts all throughout the script, so UNION (basically running another query) would be last resort for me Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 14, 2009 Share Posted August 14, 2009 http://dev.mysql.com/doc/refman/5.0/en/select.html SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [sTRAIGHT_JOIN] [sql_SMALL_RESULT] [sql_BIG_RESULT] [sql_BUFFER_RESULT] [sql_CACHE | SQL_NO_CACHE] [sql_CALC_FOUND_ROWS] select_expr [, select_expr ...] [FROM table_references [WHERE where_condition] [GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]] [HAVING where_condition] [ORDER BY {col_name | expr | position} [ASC | DESC], ...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] [PROCEDURE procedure_name(argument_list)] [iNTO OUTFILE 'file_name' export_options | INTO DUMPFILE 'file_name' | INTO var_name [, var_name]] [FOR UPDATE | LOCK IN SHARE MODE]] How many limits does it say you can set? Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted August 14, 2009 Author Share Posted August 14, 2009 Looks like one 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.