rach01 Posted July 3, 2013 Share Posted July 3, 2013 hello I have a query which is long, but the main section I have a question about is GROUP BY id ORDER BY id DESC LIMIT 10 this works ok and gives me the first 10 records in descending order, so it gets oldest to newest what do I need to do, to keep the query (first 10 records) but order by newest to oldest can anyone help me, I've searched high and low, and tried lots of ideas, but cannot get it to work right thanxs Quote Link to comment https://forums.phpfreaks.com/topic/279846-help-with-sql-ordering-in-php/ Share on other sites More sharing options...
rach01 Posted July 4, 2013 Author Share Posted July 4, 2013 does anyone know the answer? Quote Link to comment https://forums.phpfreaks.com/topic/279846-help-with-sql-ordering-in-php/#findComment-1439379 Share on other sites More sharing options...
cpd Posted July 4, 2013 Share Posted July 4, 2013 (edited) Firstly, why are you grouping by ID when ID is, or at least should be, unique? I'm not really convinced you've searched high and low as you've identified the ORDER BY is ordering your result set but haven't searched how to use it? The key word is DESC meaning descending. You'll want to change it to ASC meaning ascending. Moreover, be patient for an answer. This forum has people contributing from all over the world with different time zones so just wait 24 hours and you should have an answer! Edited July 4, 2013 by cpd Quote Link to comment https://forums.phpfreaks.com/topic/279846-help-with-sql-ordering-in-php/#findComment-1439387 Share on other sites More sharing options...
Solution Barand Posted July 4, 2013 Solution Share Posted July 4, 2013 use a subquery eg SELECT invoiceId FROM ( SELECT invoiceId FROM invoices ORDER BY invoiceID DESC LIMIT 10 ) as lastten ORDER BY invoiceId ASC; Quote Link to comment https://forums.phpfreaks.com/topic/279846-help-with-sql-ordering-in-php/#findComment-1439389 Share on other sites More sharing options...
rach01 Posted July 5, 2013 Author Share Posted July 5, 2013 thanks, your advice help Quote Link to comment https://forums.phpfreaks.com/topic/279846-help-with-sql-ordering-in-php/#findComment-1439577 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.