Jump to content

Recommended Posts

Hi,

 

Is there a way that I could order the result coming from database by the number of value is repeated?

 

for example if in the result (coming from while loop and mysql_fetch_array) I have 3 rows that "name" field is "john" ,  2 rows that "name" field is "tom" , and 5 rows that "name" field is "jack" .

 

Is there a way I could order these like it give me the  5 "jack" first (it have 5 rows) m then it give me "john" (with 3 rows), then "tom"  ?  (or asc maybe)

 

Thanks 

 

(like order by max rows ...)

Link to comment
https://forums.phpfreaks.com/topic/130840-order-by-same-rows-number/
Share on other sites

sorry sir but you didn't get the point.

 

your code will order by name, like by ordering by first letter.  I want to order same value by "how many rows it is in there.

 

I want this :

value1

value2

value1

value4

value4

value1

value5

value5

value5

value1

 

to become :

 

value1

value1

value1

value1

value5

value5

value5

value4

value4

value2

 

you see?  number of rows the value is in, value1 is repeated the most (4 times) so first, value5 is repeated 3 times, value4 is repeated 2 times  and ...

 

 

fenway I didn't exactly get it.

 

when using group by it removes duplicated values.

 

How to write this query  ?

the main thing is , I have a table called "labels" .  and another table "members" . in members table there's a field named "label" . and in label table there's a field "label_name"  . my query is this :

 

select labels.*,members.* from labels inner join members on labels.label_name=members.label

 

so I want to have the results like the label which has the most people comes first and then other ...

I'm counting the number of members of each label with php. so I need all rows of a label name come after each other  :

label_name  member      label

label4          member1    label4

label4          member4    label4

label4          member7    label4

label5          member3    label5

label5          member8    label5

label3          member2    label3

 

 

hope its clear enough.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.