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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:35:22+00:00 2026-05-12T09:35:22+00:00

The code below returns the top 25 most recently-created tables in a MySQL database.

  • 0

The code below returns the top 25 most recently-created tables in a MySQL database.

$index = mysql_query("select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='bookfeather' order by CREATE_TIME desc limit 25");

Each table has the following format:

id INT(11) NOT NULL auto_increment, site VARCHAR(350) NOT NULL, votes_up BIGINT(9) NOT NULL, votes_down BIGINT(9) NOT NULL, PRIMARY KEY(id), UNIQUE (site)

I would like to change the code to show:

  1. Top 25 tables based on number of different entries for “site”

  2. Top 25 tables based on sum of “votes_up”

How can I do this?

Thanks in advance,

John

  • 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-12T09:35:22+00:00Added an answer on May 12, 2026 at 9:35 am

    1. Top 25 tables based on number of different entries for “site”

    IIUC, “site” is UNIQUE, so you should be able to:

    select
      TABLE_NAME,
      ifnull(TABLE_ROWS, 0) as SITES
    from INFORMATION_SCHEMA.TABLES
      where TABLE_SCHEMA='bookfeather'
    order by SITES desc limit 25
    

    But substituting TABLE_ROWS for no. of unique SITE records with a wink and a nod is cheating — better to redesign. 🙂

    2. Top 25 tables based on sum of “votes_up”

    If you cannot, for whatever reason, follow the excellent advice to redesign, you’ll have to programatically iterate over each table. In your code you might loop over SHOW TABLES, accumulating the result of

    select 'tblName', ifnull(sum(VOTES_UP), 0) as UPVOTES from tblName
    

    sorting on the second field of your accumulated rows and pruning to the top 25.

    A variant of this involves a summary table which keeps track of tables and sum()’d UPVOTES, perhaps re-written periodically by cron, updated on the fly by per-table triggers, or presented in a VIEW (re-CREATEd for each new table) which is a UNION of all constituent queries.

    But don’t do any of this. 🙂 Switch to a single-table design (perhaps asking your storage engine to partition, if that’s a concern).

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

Sidebar

Ask A Question

Stats

  • Questions 161k
  • Answers 161k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since web browsers will render the content differently, your only… May 12, 2026 at 11:44 am
  • Editorial Team
    Editorial Team added an answer Use: SET NOCOUNT ON to suppress these messages and use… May 12, 2026 at 11:44 am
  • Editorial Team
    Editorial Team added an answer Yep, definitely. $className = 'MyClass'; $object = new $className; May 12, 2026 at 11:44 am

Related Questions

I am trying to make a few php scripts that will run among other
I have a login form which appears at the top of all of my
I've run into a really strange bug, that I'm hoping someone can explain. I
Let's assume, for instance, an xHTML document as below: <html> <head> </head> <body> <div
I want to send keyboard input to a window in another process, without bringing

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.