Hassan Munir Hassan Munir - 1 year ago 60
MySQL Question

Want to query in array and get result of ids that been passed into query

I made a query which returns me array of ids. like below :

.order('count(*) DESC')

this return me following result

[175, 174, 176, 173, 172]

Now i want to find question with same ids and exactly in same order. I am querying in following way.

.order('count(*) DESC')

this return me following result:

[172, 173, 174, 175, 176]

As you can see ids not in order like i pass in query. I want to get result exactly in same fashion as i querying in.

Answer Source

If you want to order questions according to number of its associated answers then I think you can do like this

  .select("users.*, count(annswers.id) as scount")
  .order("scount DESC")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download