I might have misunderstood the question...
would this work: ?
#!/usr/bin/perl -w
use strict;
my %DataBase;
while(<>)
{
$DataBase{$_}++ if /(?<!from )INSERT INTO Photo/;
};
open OUT, ">results.txt" or die $!;
print OUT for sort keys %DataBase;
close OUT;