in reply to SQL Select

Is @all_id created by another SQL query ?

poj

Replies are listed 'Best First'.
Re^2: SQL Select
by Scully4Ever (Novice) on Feb 03, 2016 at 23:24 UTC

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

      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

      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 );