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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:04:17+00:00 2026-06-12T16:04:17+00:00

I have a table that holds allocations of problem reports (PRs) as follows: TABLE

  • 0

I have a table that holds allocations of problem reports (PRs) as follows:

TABLE "ALLOCATIONS"

ALLOCATIONID    PRID    DATEALLOCATED        ENG_ID
1               401     20-SEP-06 10.48.00   1
2               401     20-SEP-06 10.48.00   2
3               401     20-SEP-06 10.48.00   2
4               402     20-SEP-06 12.35.00   1
5               402     20-SEP-06 12.43.00   1
6               402     20-SEP-06 13.43.00   2
7               700     14-OCT-12 13.30.05   1
8               700     14-OCT-12 13.30.35   2
9               700     14-OCT-12 14.30.35   2

The most recent allocation determines which engineer the PR is now assigned to. I want to find all the PRs that are assigned to engineer 2 for example.
So I look for the most recent allocation for each PRID, check the ENG_ID, then pull out the information from this table if the ENG_ID is correct.

This table contains the actual PR descriptions (and other info omitted here for clarity).

TABLE "PROBLEMS"

PRID     TITLE
401      Something
402      Something
700      Something

To do this I have used the DATEALLOCATED field as follows:

SELECT PRID, TITLE FROM PROBLEMS p WHERE p.PRID IN
(
    SELECT GROUPEDALLOC.PRID FROM allocations alloc INNER JOIN
    ( 
        SELECT PRID, MAX(DATEALLOCATED) AS MaxAllocationDate    
        FROM allocations   
        GROUP BY PRID
    ) 
    groupedAlloc ON alloc.PRID = groupedAlloc.PRID 
    AND ALLOC.DATEALLOCATED = groupedAlloc.MaxAllocationDate 
    AND ENG_ID = 2
) 
ORDER BY PRID DESC;

Now this works fine for records 7,8,9 above which were inserted with a long date format that includes the seconds, however for the older records which didn’t log the seconds this will obviously not work. For these records I want to fall back on the allocationID (which may or may not be sequential obviously – however it is a last resort and better than nothing).

My question is, how do I modify my query to perform this extra condition on the DATEALLOCATED (i just want to see if they are all equal for a particular PRID), and then use the ALLOCATIONID instead?

I am using OracleXE but I want to stick to standard SQL if possible.

  • 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-12T16:04:18+00:00Added an answer on June 12, 2026 at 4:04 pm

    Does this do it for you ?

    WITH 
      BY_DATE
      AS (SELECT PRID, MAX (DATEALLOCATED) AS MAXDATE FROM ALLOCATIONS GROUP BY PRID),
    
      BY_ALLOC
      AS (SELECT A.PRID, MAXDATE, MAX (ALLOCATIONID) AS MAXALLOC
            FROM ALLOCATIONS A JOIN BY_DATE B ON 
                 A.PRID = B.PRID AND 
                 A.DATEALLOCATED = B.MAXDATE
          GROUP BY A.PRID, MAXDATE)
    
    SELECT A.PRID, A.ENG_ID
      FROM ALLOCATIONS A JOIN BY_ALLOC B ON 
           A.ALLOCATIONID = B.MAXALLOC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I have a table that holds vehicle information and one of those
i have a table that holds my users information like username , password ,
I have a MySQL table that holds many entries with repeated IDs (for various
Hi I have a datatables based table that holds data. I need to be
I have a table (table variable in-fact) that holds several thousand (50k approx) rows
Lets suppose that I have a Category table with a column that holds the
I have a configuration table, that holds the values selected by a specific user.
I have one table that holds my ressources: Ressource | Ressource-ID And a table
I have a table that holds data like key val Product Oranges Customer Alan
I have a table that holds nested categories. I want to avoid duplicate names

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.