Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Query using aggregate max function returning inconsistent results

Melissa LittleJun 7 2025

I have a query that is returning inconsistent results generally it works just fine but in some cases it does not return the correct results. Below is the dummied up query

SELECT max(trans_id), item_id FROM product_sales

WHERE location_ id = 1234

   AND purchase\_dt ≤ LAST\_DAY(TO\_DATE('05/01/2025','MM/DD/YYYY'))

   AND sent\_dt is null    

   AND trans\_status <> ā€˜S’     

GROUP BY item_id;

Trans_id Item_id trans_status purchase_dt sent_dt location_id

1234 222 P 05/01/2025 null 1234

1235 222 P 05/01/2025 null 1234

Now what should come back is the record with trans_id =1235 and what is coming back is trans_id = 1234. Any ideas? My only thought is to create a view to break up the processing? Does the database need to be tweeked to handle this? This is by no means a monster database.

Comments
Post Details
Added on Jun 7 2025
7 comments
234 views