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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:37:53+00:00 2026-06-16T02:37:53+00:00

I have some logs tables with the same structure. Each tables is related to

  • 0

I have some logs tables with the same structure. Each tables is related to a site and count billion of entries. The reason of this split is to perform quick and efficient query, because 99.99% of the query are related to the site.

But at this time, I would like to retrieve the min and max value of a column of these tables?

I can’t manage to write the SQL request. Should I use UNION?

I am just looking for the request concept, not the final SQL request.

  • 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-16T02:37:54+00:00Added an answer on June 16, 2026 at 2:37 am

    You could use a UNION, yes. Something like this should do:

    SELECT MAX(PartialMax) AS TotalMax
      FROM 
      ( SELECT MAX(YourColumn) AS PartialMax FROM FirstTable UNION ALL SELECT MAX(YourColumn) AS PartialMax FROM SecondTable ) AS X;
    

    If you have an index over the column you want to find a MAX inside, you should have very good performance as the query should seek to the end of the index on that column to find the maximum value very rapidly. Without an index on that column, the query has to scan the whole table to find the maximum value since nothing inherently orders it.

    Added some details to address a concern about “enormous queries”.

    I’m not sure what you mean by “enormous”. You could create a VIEW that does the UNIONs for you; then, you use the view and it will make the query very small:

    SELECT MAX(YourColumn) FROM YourView;
    

    but that just optimizes for the size of your query’s text. Why do you believe it is important to optimize for that? The VIEW can be helpful for maintenance — if you add or remove a partition, just fix the view appropriately. But a long query text shouldn’t really be a problem.

    Or by “enormous”, are you worried about the amount of I/O the query will do? Nothing can help that much, aside from making sure each table has an index on YourColumn so that maximum value on each partition can be found very quickly.

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

Sidebar

Related Questions

I have a stored procedure that logs some data, how can I call this
I have some child processes which should write some logs into a common file.
i have some apache logs and i want to be able to query the
I have some troubles while writing logs from log4net to the file. I seem
I have a windows service that generates logs as it does some execution. I
I see an application have used Log.info = some info where are these logs
I have the following situation: i need to create some temporary tables to optimize
I have a .txt file that logs some information. I want to load it
After viewing my prod logs, I have some error mentionning : [2012-08-31 15:56:43] request.CRITICAL:
We have a small project that involves automatically parsing some server/mail logs (among other

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.