Jump to content

Order By Number Of Entries


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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...