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

  • Home
  • SEARCH
  • 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 7991247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:14:15+00:00 2026-06-04T13:14:15+00:00

This query works.. for querying 50 mysql databases at once and returning the most

  • 0

This query works.. for querying 50 mysql databases at once and returning the most recent 10 results, but.. is there a way to not query the entire database of each state (only 4 states listed in my example), just get the top 10 (by timeStamp desc) and make this query far more efficient?

$query = "    
SELECT imgURLThumb, timeStamp, title2, state, postId, title
FROM (
  SELECT imgURLThumb,timeStamp, title2, state, postId, title FROM db_washington.md_postings UNION ALL 
  SELECT imgURLThumb,timeStamp, title2, state, postId, title FROM db_westvirginia.md_postings UNION ALL 
  SELECT imgURLThumb,timeStamp, title2, state, postId, title FROM db_wisconsin.md_postings UNION ALL 
  SELECT imgURLThumb,timeStamp, title2, state, postId, title FROM db_wyoming.md_postings 

) allposts where imgURLThumb <> 'images/nopicture.png' order by timeStamp DESC LIMIT 0 , 10";
  • 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-04T13:14:17+00:00Added an answer on June 4, 2026 at 1:14 pm

    You should redesign your database so that all the postings are in a single database to make this query much easier to write. It looks like a bad design to have a database for each state. You should instead have a single table md_postings for all postings, where one of the fields is State.

    If that’s not possible then I think you have a trade-off:

    • Concise and readable SQL or
    • Good performance.

    If you want better performance try this:

    SELECT imgURLThumb, timeStamp, title2, state, postId, title
    FROM (
        (SELECT imgURLThumb,timeStamp, title2, state, postId, title
        FROM db_washington.md_postings
        WHERE imgURLThumb <> 'images/nopicture.png'
        ORDER BY timeStamp DESC
        LIMIT 10)
    
        UNION ALL
    
        (SELECT imgURLThumb,timeStamp, title2, state, postId, title
        FROM db_westvirginia.md_postings
        WHERE imgURLThumb <> 'images/nopicture.png'
        ORDER BY timeStamp DESC
        LIMIT 10)
    
        UNION ALL
    
        (SELECT imgURLThumb,timeStamp, title2, state, postId, title
        FROM db_wisconsin.md_postings
        WHERE imgURLThumb <> 'images/nopicture.png'
        ORDER BY timeStamp DESC
        LIMIT 10)
    
        UNION ALL
    
        (SELECT imgURLThumb,timeStamp, title2, state, postId, title
        FROM db_wyoming.md_postings
        WHERE imgURLThumb <> 'images/nopicture.png'
        ORDER BY timeStamp DESC
        LIMIT 10)
    ) AS allposts
    WHERE imgURLThumb <> 'images/nopicture.png'
    ORDER BY timeStamp DESC LIMIT 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm logging output with log = /var/log/mysql/query.log and this works ok, but I only
Im not good in querying. I would like to ask if this query works.
I have this query which works correctly in MySQL. More background on it here
This has to be obtained from a remote machine. The following query works not
I'm having this Mysql query, It works: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT
This query works: item = db.GqlQuery(SELECT * FROM Item WHERE CSIN = 13)[0] although
I have problems running a dynamic LIKE statement in my project: this query works
I know this particular query works, as I tested it with unprepared, procedural methods.
So I have this query that works perfectly: SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories FROM
I have this linq query that works well (although it may be written better,

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.