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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:32:14+00:00 2026-06-09T12:32:14+00:00

first off: thanks for looking; your time is appreciated! to the point: SCHEMA: for

  • 0

first off: thanks for looking; your time is appreciated!

to the point:

SCHEMA: for myTable

nonUniqueID    YEAR    MONTH    DAY    HOUR    numericValue
1              2012    01       01     01      99.9
1              2012    01       01     02      65.2
1              2012    01       01     03      -88
7              2012    02       08     21      9.08
1              2012    01       01     09      99.913
1              2013    01       01     01      99.999999

Basically, it’s two values nonUniqueID and numericValue with a granular date.

Now, i need to get the single greatest date in this entire database. With the data above, the expected result would be:

nonUniqueID    YEAR    MONTH    DAY    HOUR    numericValue
1              2013    01       01     01      99.999999

Because this is SQLite, i know that i will end up having to use MAX() several times. The order will have to be MAX(YEAR) then MAX(MONTH) then MAX(DAY) then MAX(HOUR).

Basically, the query would work like this (i just don’t know enough about SQL syntax to create the query):

  1. Find all records with highest YEAR
  2. From this set, find all records with highest MONTH
  3. From this set, find all records with highest DAY
  4. From this set, find all records with highest HOUR
  5. return this record

Here is a SQL that i adapted from another StackExchange question that does not work

Select * From ( 
    Select max(YEAR) as Y FROM myTable 

    union 

    Select max(MONTH) as M FROM myTable 

    union 

    Select max(DAY) as D FROM myTable 

    union

    Select max(HOUR) as H FROM myTable 
) myTable;

which returns

Y
-----
21 
08 
02 
2013

Compare this to expected out:

nonUniqueID    YEAR    MONTH    DAY    HOUR    numericValue
1              2013    01       01     01      99.999999

it returned 4 records instead of the one record with the 4 values.

Can somebody please help me with my query? THANK YOU!

  • 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-09T12:32:15+00:00Added an answer on June 9, 2026 at 12:32 pm

    Try this

     SELECT nonUniqueID ,  YEAR ,  MONTH ,  DAY ,  HOUR ,  numericValue FROM myTable as a
     INNER JOIN (Select max(MONTH) FROM  myTable) as b
     ON a.YEAR = B.YEAR
     INNER JOIN (Select max(DAY) FROM myTable) as c
     ON b.YEAR = c.YEAR
     INNER JOIN (Select max(HOUR) FROM myTable) as d
     ON c.YEAR = d.YEAR
     WHERE a.YEAR = (Select max(YEAR) FROM myTable) 
    

    It returns 4 values because you use UNION
    it means that the result are join in one column

    EDIT

    Ive just updated my answer see if that works Im not quite sure to the performance of this query

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

Sidebar

Related Questions

First off, thanks in advance for your help. This issue is driving me nuts.
First off, thanks for reading my question! Secondly, I am looking at developing the
First off thanks to all the users who have made my android developing adventure
First off, let me thank you if you're taking the time to look at
First off, I want to thank you for looking into my question as I
First off, greetings everyone and thank you for your interest in my question. I'm
Ok, I tried holding off and looking for answers, but I need your guys'
First off, I'm sorry if the title doesn't explain this very well. I'm looking
first off I'm a noob to PHP but here is my problem. I am
First off, I'm coming (back) to Java from C#, so apologies if my terminology

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.