I'm fairly sure you'd need a script.
my $sth = $DB->table('Links','CatLinks')->select;
while (my ($rec) = $sth->fetchrow_hashref) {
$data{$rec->{Title}} = [];
push @{$data{$rec->{Title}}}, $rec->{CategoryID};
}
...what that will do is make a hash of all link titles and will store their category ids.
Then what you can do it remove any entries where there is only one category, as this means the link isn't a duplicate....
Then you can sort all values by category id and remove the lowest id which you want to keep....
shift @{$data{$key}};
@{$data{$key}} = sort @{$data{$key}};
}
...then go on to delete everything.
foreach my $ids (@{$data{$key}}) {
$DB->table('CatLinks')->delete({ CategoryID => $ids });
}
}
I've done that step by step so you can see. I may have it totally wrong but it's the best I can do at the moment
If you *do* try it - make sure you have a backup.
Code:
my %data; my $sth = $DB->table('Links','CatLinks')->select;
while (my ($rec) = $sth->fetchrow_hashref) {
$data{$rec->{Title}} = [];
push @{$data{$rec->{Title}}}, $rec->{CategoryID};
}
...what that will do is make a hash of all link titles and will store their category ids.
Then what you can do it remove any entries where there is only one category, as this means the link isn't a duplicate....
Code:
my %unique = map { $_ => $data{$_} } grep scalar @{$data{$_}} > 1, keys %data;Then you can sort all values by category id and remove the lowest id which you want to keep....
Code:
foreach my $key (keys %data) { shift @{$data{$key}};
@{$data{$key}} = sort @{$data{$key}};
}
...then go on to delete everything.
Code:
foreach my $key (keys %data) { foreach my $ids (@{$data{$key}}) {
$DB->table('CatLinks')->delete({ CategoryID => $ids });
}
}
I've done that step by step so you can see. I may have it totally wrong but it's the best I can do at the moment
If you *do* try it - make sure you have a backup.