I have the following simple table:

CustomerID  CustomerName   NumOfOrders
1           Joe            15
2           Jane           20
7           Clara          1

I want to find the customer with maximum number of orders. Seems trivial enough but I can,t seem to find a solution.

Use ORDER BY NumOfOrders DESC LIMIT 1

hello can i intercept this thread?

which is faster select max(NumOfOrders) from table

or

select NumOfOrders from table order by NumOfOrders desc limit 1

Why don't you profile that query, I think it depends on whether you're using the right index.

Select Top 1 CustomerID,CustomerName, NumOfOrders from Table order by NumOfOrders desc

TOP 1 is used in MS SQL Server, not MySQL.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.