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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:25:31+00:00 2026-06-15T00:25:31+00:00

I have a large table I have been playing with the query analyzer and

  • 0

I have a large table I have been playing with the query analyzer and looking for the best way to do this.

The table is like this:

name         rows        reserved     data         index_size   unused
table_name   110980132   7802944 KB   6119784 KB   1679320 KB   3840 KB

And has these columns:

 ID int, time_stamp datetime, value1 float, value2 float, value3 float.... 

These time_stamps are dates with times. I need to find an easy way, without storing anything, to be able to get just the date portions for the table. Eventually, I may need to know just the day + hour part (and not the whole time portion). At the moment, I just need to know what the last 30 days we had data for are (sometimes days are missing at this point, this question/query will ultimately not just be looking for the last x days, but all the days, or whatever).

What is the best way to do this considering performance and time? I’ve played with group by, distinct, top x, rank(), temp tables, views… some things are better than others but nothing I am doing seems to be great.

Ideas? Thanks!

  • 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-15T00:25:33+00:00Added an answer on June 15, 2026 at 12:25 am

    If you’re open to using T-SQL batches, instead of a single query, then you can make use of indexes like this:

    create table #tmp (date datetime primary key clustered);
    declare @pivot datetime;
      insert #tmp
      select TOP(1) datediff(d,0,time_stamp)
        from tbl
    order by time_stamp desc;
    while @@rowcount > 0 and (select count(*) from #tmp) < 30
    begin
          insert #tmp
          select TOP(1) datediff(d,0,time_stamp)
            from tbl
           where time_stamp < (select min(date) from #tmp)
        order by time_stamp desc;
    end;
    

    All this requires of you is a good index on time_stamp, and it will perform exactly 30 seeks (or less) on that index. Very surgical and quick. I threw it up as a concept, so obviously the 2 scalar subqueries in there can be easily optimised.

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

Sidebar

Related Questions

I have a large table with around half a million rows which is taking
I have a large table (between 74 and 88million rows) which is the middle
I have a large table (~1M rows now, soon ~10M) that has two ranked
I have a large mysql MyISAM table with 1.5mil rows and 4.5GB big, still
I have a large table and allow the user to hide rows based upon
I have a very large HTML table containing 1500 rows (markup produced by PHP).
I commonly have to query an extremely large table for multiple variables with many
I have a really large table (around 32 columns and 1000+ rows) which I'm
I'm not sure if I'm phrasing this in the best way but I have
I have a large table stored in mysql (basically, a log) that looks like

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.