i have a table ‘tbl_orders’, that table contains the folllowing
order_id | customer_id | grand_total
now i need to fetch out the TOP 5 customer which have more orders with me
i try the query below,
"SELECT customer_id , count(customer_id) as total_orders FROM `tbl_order` group by customer_id"
But this query only give me all customer_id & total_orders of each customer & i want to fetch TOP 5 customer, i.e having more orders with me
Adding to DonCallisto’s answer, you might want to also sort by the highest number of orders. Otherwise you won’t get the top 5.
Notice I also changed the count column from customer_id to order_id. This doesn’t make any difference functionally, but it makes more sense to someone reading your code.