rmpotter 0 Posted October 22, 2009 Report Share Posted October 22, 2009 (edited) Currently I am attempting to pull some data using:$sql="select * from inspect_erp where inspection_id = ".$myid." ORDER BY erp_type";the fields in the table areerp_id, inspection_id, erp_type, gpslocationBasically, I am looking to alter this to have the SQL order by the most commonly occurring erp_type to the least occuring. Can anyone help me out? Edited October 22, 2009 by rmpotter Quote Link to post Share on other sites
Kameloh 0 Posted October 22, 2009 Report Share Posted October 22, 2009 (edited) $sql = "SELECT * FROM inspect_erp WHERE inspection_id='$myid' ORDER BY erp_type DESC"; you can probably add ASC or DESC right after erp_type - unless you wanted something else more specific? Edited October 22, 2009 by Kameloh Quote Link to post Share on other sites
justsomeguy 1,135 Posted October 22, 2009 Report Share Posted October 22, 2009 I don't think you're able to do that with one query, you'll have to do one query to get the erp_types and the number of times they appear, and one or more other queries to get the items for each type. Quote Link to post Share on other sites
rmpotter 0 Posted October 22, 2009 Author Report Share Posted October 22, 2009 I don't think you're able to do that with one query, you'll have to do one query to get the erp_types and the number of times they appear, and one or more other queries to get the items for each type.Unfortunately, that's what I figured. I will fool around with it an post a solution for anyone interested. Quote Link to post Share on other sites
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.