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!

Query to fetch 10 sample records of each type

614170Apr 13 2009 — edited Apr 13 2009
Hi,
i have a table that has a column called TYPE. this can have values like B, F, I, U etc(can be more). i need a query that will return me 40 sample records 10 for each type. the sample records can be any random rows.

right now i have 4 queries for each TYPE and i am doing a UNION ALL to all the queries. i am getting the result i need but this will scan the table 4 times and is not good performance wise.
select na.match_type as move_type, na.new_address_flag as is_new_address,
na.address_line_1_orig, na.new_street_address, na.address_line_2_orig,
na.new_address_line2, na.apt_nbr_orig, na.new_apt_nbr, na.city_orig,
na.new_city, na.state_orig, na.new_state, na.zip_code_orig, na.new_postal_code,
na.zip_plus_4_orig, na.new_postal_plus_cd
from ncoa_audit na
where match_type = 'B'
and rownum < 11

Can someone please help on this.

Thanks,
This post has been answered by Centinul on Apr 13 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 11 2009
Added on Apr 13 2009
6 comments
1,153 views