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!

Inconsistent result from subquery using max function - database bug?

BluecloudNov 8 2012 — edited Nov 13 2012
Two queries with same subquery did not return same counts. The first query returns correct number of counts. The second one returns more counts.

query 1 - correct counts
select max(rownum) from
(select c_day, b_num, max(gap), max(postingdate) from block_gap
group by c_day, b_num having max(gap)>=1 and max(postingdate)<20051102)
MAX(ROWNUM)
----------------------
329658

query 2 - Incorrect counts
select count(*) from
(select c_day, b_num, max(gap), max(postingdate) from block_gap
group by c_day, b_num having max(gap)>=1 and max(postingdate)<20051102)
COUNT(*)
----------------------
361002

I tried to find why the second query returned more items than first one by running the following queries and found that the seond query returned some items which contains postingdate >20051102, and it is incorrect return.
select c_day, b_num, max(gap), max(postingdate) from block_gap
group by c_day, b_num having max(gap)>=1 and max(postingdate)<20051102
correct result - return 329658 rows


select * from (
select c_day, b_num, max(gap), max(postingdate) from block_gap
group by c_day, b_num having max(gap)>=1 and max(postingdate)<20051102)
wrong result - return 361002 rows
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2012
Added on Nov 8 2012
16 comments
1,658 views