Jump to content

Order By Number Of Entries


rmpotter
 Share

Recommended Posts

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 by rmpotter
Link to comment
Share on other sites

$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 by Kameloh
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...