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.

Recommended Answers

Use ORDER BY NumOfOrders DESC LIMIT 1

Jump to Post

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

Jump to Post

All 5 Replies

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
Be a part of the DaniWeb community

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