Jump to content

Order By Number Of Entries


rmpotter

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?

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...