Re: anti-join with SQL::Statement?

[email protected] (Darren Duncan)
Newsgroups perl.dbi.users
Message-ID <[email protected]>
Reiner, I don't know if this was your workaround, but here's another solution 
that just uses SQL::Statement ...

Ludwig, Michael wrote:
>> So the next thing I tried was the anti-join (see
>>
>>   http://en.wikipedia.org/wiki/Relational_algebra#Antijoin
> 
> First time I hear of this "antijoin".
> 
> The example given on the Wiki page doesn't make much sense
> to me. Isn't is simply an OUTER JOIN where you're looking
> for NULL on the right-hand side?
> 
> SELECT E.Name, D.DeptName
> FROM Employee AS E
> LEFT JOIN Dept AS D ON E.DeptName = D.DeptName
> WHERE D.DeptName IS NULL

An "antijoin", aka "anti-semijoin", aka "semidifference" will filter one rowset 
to retain just the rows that don't have matching rows in the other one.  The 
closest SQL analogy is

"SELECT ... FROM source WHERE ... NOT IN (SELECT ... FROM filter)"

But yes, Michael's solution is basically correct, and here's a closer variant of 
what antijoin does:

   SELECT E.*
   FROM Employee AS E
     LEFT JOIN Dept AS D USING (DeptName)
   WHERE D.DeptName IS NULL

The key difference here is that the result of an antijoin is all of the columns 
of the source table and only those.

Reiner, you're probably better off to just use this SQL solution if you can.

Set::Relation is superfluous for this task actually.

-- Darren Duncan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.