Query to fetch 10 sample records of each type
614170Apr 13 2009 — edited Apr 13 2009Hi,
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,