I have the requirement to print the first record of the $sql_pr based on differnent values of "seg_dtl_id" so that when the "while loop" ends, i have the file with the pan_id belongs to respective "seg_dtl_id" printed in the respective column seperated by "|" like below.
here 8000,8001,8002,8003,8004 are pan_ids belong to a single seg_dtl_id and so and so forth. i can make it with the help of below code but the problem arises when it comes to performance as the code executes the same sql multiple times.Say if number of records are 1 million, the sql has to run 1 million times thereby making performance issues.
please note am using basic version of perl (perl5/lib/5.00503) and guide me to reconstruct the code to overcome this problem.
my $index = 0;
my $n = 0;
my $sql_ct = "select max(count(pan_id)) from seg_dtl_panelist where s
+eg_id ='1' group by seg_dtl_id, seg_id";
my $rs_ct = $db->query($sql_ct);
while ($n < $$rs_ct)
$sql = "select seg_dtl_id from segmentation where seg_id = '1'";
$rs = $db->query($sql);
my $dtl_id = $$_ ;
$sql_pr = "select pan_id from seg_dtl_panelist where seg_dtl_id = '$
+dtl_id' and seg_id = '1'";
$rs_pr = $db->query($sql);
print file "$$rs_pr[$index]|";
print file "\n";