Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:54:22+00:00 2026-06-03T20:54:22+00:00

i have a table ‘tbl_orders’, that table contains the folllowing order_id | customer_id |

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:54:24+00:00Added an answer on June 3, 2026 at 8:54 pm

    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.

    SELECT customer_id , count(order_id) as total_orders 
    FROM `tbl_order` 
    GROUP BY customer_id 
    ORDER BY total_orders DESC
    LIMIT 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table that contains a full mailing address for customers. I'd like to
I have table with around 70 000 rows. There is 6000 rows that i
I have table of data that is sorted as follows: Item | Sample |
I have table with column Percentage varchar(10) Data in that table is Pecentage 2/10
I have table A(id). I need to create table B(id) add a foreign key
i have table AuditLog with fields including: audited_id | audited_type That results in data
I have table structures that include a composite primary key of id & revision
I have table in sqlalchemy 0.4 that with types.DateTime column: Column(dfield, types.DateTime, index=True) I
I have table with two SelectOneMenu in row. I need populate data in second
I have table 'pages' in my database. I have noticed that cakePHp has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.