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 4585412
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:29:28+00:00 2026-05-21T21:29:28+00:00

I have a table with ~100,000 rows. I am trying to print to screen

  • 0

I have a table with ~100,000 rows.

I am trying to print to screen the most frequently used “type_num” from a column.

So if 2362 appears 1000 times in the type_num column, that being the most used type, and 1234 is used 987 times and so on, I get a desc list of most freq used type_num‘s.

No luck. Here is my newbie attempt:

 my $mostused = DBI->connect("$thedb","$user","$password") or die "Connection Error: $DBI::errstr\n";

  my $getfreq = $mostused->prepare(qq{SELECT `type_num` count(*) FROM `productstable` GROUP BY `type_num` ORDER BY count(*) DESC LIMIT 10}); ##just tested with 10

    $getfreq->execute() or die "Connection Error: $DBI::errstr\n";

    while(my ($type_num) = $getfreq->fetchrow_array()) {
    print qq~$type_num<br />~;
    }

    $getfreq->finish(); #not sure if correct
    $mostused->disconnect;  #not sure if correct

Connection Error: You have an error in
your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near ‘count(*) FROM `productstable`
GROUP BY `type_id` ORDER BY count(*)
DESC LIMIT 10’ at line 1

The type_num’s are a 1 to 5 digit number. (Using DBI and strict but this example is cleaned up.)
I have tried several variations and examples I found while searching here but, I am doing something wrong. please help.

  • 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-05-21T21:29:29+00:00Added an answer on May 21, 2026 at 9:29 pm

    Change

    SELECT `type_num` count(*) 
    FROM `productstable` GROUP BY `type_num` 
    ORDER BY count(*) DESC LIMIT 100
    

    To

    SELECT `type_num`, count(*) as cnt 
    FROM `productstable` GROUP BY `type_num` 
    ORDER BY cnt DESC LIMIT 100
    

    Comma after type_num + alias for count(*) to reuse in the ORDER BY.

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

Sidebar

Related Questions

I have a table with about 100.000 rows that used to look more or
I have 100 tables, 40,000 rows in each table. I want to go into
I have a table with around 100,000 rows at the moment. I want to
I have a question when I try to remove over 100,000 rows from a
Guys I'm stumped on this one, I have a large table with 100,000 rows
I have a table in which approx 100,000 rows are added every day. I
MySQL/ASP - Delete Duplicate Rows I have a table with 100,000 rows called 'photoSearch'.
I have a temp table with 13,000 rows. Most of the rows have a
I have a table (rowID, name, familyName) with at least 100.000 rows (SQLite). I
I have a SharePoint external list that points to a 100,000 record SQL table.

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.