Muhammad Baber Zaman
Muhammad Baber Zaman

Reputation: 122

Get The Maximum Number of records from a specific ID in mysql

What I want is, To get the TOP Customers according to their Orders they have made from the Database. It is not based on SUM of any column in database. It should be according to number of records. Suppose a CustomerID has placed 15 orders. And another CustomerID has 10 Orders The 15 Orders ID should above and 10 Should below. I am trying with mysqli but It is not possible for me to do it. What I am doing is just to get mysqli_num_rows() and My MySqli query is

SELECT * FROM  Reservations GROUP BY CustomerID

How I can get the result having Maximum Records top and Minimum Records lower.

Image is Here

Please see the Above image to understand what I am searching for

Upvotes: 0

Views: 158

Answers (1)

BukhariBaBa
BukhariBaBa

Reputation: 169

select *, count(CustomerID) c from Reservation
group by CustomerID
order by c desc;

first, make a group by and make the order as you want ASC or DESC

Upvotes: 1

Related Questions