Customer Placing the Largest Number of Orders

Write an SQL query to find the customer_number for the customer who has placed the largest number of orders.

table name: Orders


Question Explanation: 

  • We have given a table named orders in which order_number is primary key. But customer_number can have repeated  values based on how many times customer has ordered something.. 
  • Each time when a particular customer will order something a new record is going to be added with particular cutomer_number and unique order_number.
  • Our task is to find a customer who has placed order maximum times.

Solution Explanation:

  • Since, customer_number is repeated multiple times. We are going to apply group by clause on customer_number. It wil create different groups for each unique customer_number.


  • Then we will count number of rows in each group.
select COUNT(order_number),customer_number from Orders
group by customer_number 


  • Order by count(rows) descending.
select COUNT(order_number),customer_number from Orders
group by customer_number 
ORDER BY COUNT(order_number) desc

  • Select top 1 customer_number.

Final Solution:

select top 1 customer_number from Orders
group by customer_number
ORDER BY COUNT(order_number) desc

Output:


SQL Script:

CREATE TABLE [dbo].[Orders](
       [order_number]
[int] NULL,
       [customer_number]
[int] NULL
) ON [PRIMARY]
GO
INSERT [dbo].[Orders] ([order_number], [customer_number]) VALUES (1, 1)
GO
INSERT [dbo].[Orders] ([order_number], [customer_number]) VALUES (2, 2)
GO
INSERT [dbo].[Orders] ([order_number], [customer_number]) VALUES (3, 3)
GO
INSERT [dbo].[Orders] ([order_number], [customer_number]) VALUES (4, 3)
GO


Comments (9)
james_brown - 03/10/2026 06:38
Good day, I came across your website and I'm interested in finding out more about what you offer. Would appreciate a call back to discuss further. Looking forward to hearing back.
frank_johnson - 09/10/2026 08:55
Hi there, I came across your website and I'm interested in finding out more about what you offer. Please get in touch when you have a moment. Thank you!
rachelgomez68 - 09/10/2026 21:45
Hi, I'd like to learn more about your services and how they could fit my needs. Please let me know what details you need from me to proceed. Thanks!
hernandez.noah - 12/10/2026 22:20
Good day, I came across your website and I'm interested in finding out more about what you offer. Please contact me when convenient — happy to share more context. Best regards.
dcampbell864 - 16/10/2026 08:39
Good day, I have a few questions about pricing, availability, and the general process of working with you. Could someone reach out at your earliest convenience? Thanks in advance.
kenneth_scott - 19/10/2026 04:56
Good day, I'm exploring options for an upcoming project and would like to receive more information. Please reach out at your earliest opportunity. Thank you for your time.
jack_bauer - 20/10/2026 08:02
Hello, I'm interested in scheduling a brief consultation to discuss my situation in more detail. Could someone reach out at your earliest convenience? Thanks in advance.
raymondking60 - 21/10/2026 13:21
Hi there, I'd like to learn more about your services and how they could fit my needs. Please contact me when convenient — happy to share more context. Best regards.
chavez.matthew - 02/11/2026 14:20
Hi, I'd like to receive a quote for your services and understand the typical timeline. Please let me know what details you need from me to proceed. Thanks!