in reply to Re: SQL Select
in thread SQL Select

Yes, @all_id is pulled from a different table. I have to use those values to find matching parts in the current table.

Replies are listed 'Best First'.
Re^3: SQL Select
by poj (Abbot) on Feb 04, 2016 at 14:14 UTC

    If the ids are in another table (eg table_id) then you could use a join (inner) to filter the results. Here's an example using SQL::Abstract::More

    #!perl use strict; use DBIx::Simple; use SQL::Abstract::More; my $dbh = '....'; # connect $dbh->abstract = SQL::Abstract::More->new(); my @ww = qw/a b c/; my @data = $dbh->select( -from => [ -join => qw/table id=id table_id/], -columns => ['part'], -where => { ww => {-in => [@ww] }, part => {-not_like => '0000000%'} }, -union => [ -columns => ['n'], -where => { ww => {-in => [@ww] }, part => {-like => '0000000%'} } ], -group_by => ['part'], )->flat; print 'The uin count is '.scalar @data."\n";
    poj
Re^3: SQL Select
by chacham (Prior) on Feb 04, 2016 at 15:23 UTC

    Finding records in one table that exist in another is what IN() and EXISTS() are for. In general, if the column(s) are indexed, EXISTS() will be more efficient.

    SELECT Id, col2, col3 FROM Data WHERE EXISTS ( SELECT * FROM All_Id WHERE Data.Id = All_Id.Id );