in reply to Re^2: Comparing CSV files
in thread Comparing CSV files

Fascinating - I've never seen the minus keyword for SQL yet. Up to day, I've always used left outer joins to find out the missing parts between two sets of keys:

-- in table2 but not in table1: SELECT r.id FROM table2 AS r LEFT JOIN table1 AS l ON r.id = l.id WHERE r.system = ? and l.id IS NULL and r.id IS NOT NULL -- in table1 but not in table2: SELECT l.id FROM table2 AS l LEFT JOIN table1 AS r ON l.id = r.id WHERE l.system = ? and l.id IS NOT NULL and r.id IS NULL SQL

SQLite doesn't seem to document the minus keyword, so I'll stay with my (left) outer join solution, as SQLite doesn't support the full outer join. Of course, I haven't checked whether DBD::CSV supports outer joins, and I guess it doesn't jZed tells me it does, so these two SQL statements will be put to more and more use. How convenient if your whole business logic can be expressed in two SQL statements.

Replies are listed 'Best First'.
Re^4: Comparing CSV files
by jZed (Prior) on Oct 15, 2004 at 14:04 UTC
    Yes MINUS does look inteteresting. AFAIK it isn't available for MySQL, PostgresSQL, SQLite, or mentioned in ANSI SQL.

    As for DBD::CSV, pg is correct that it lacks subselects, but it does support NATURAL, INNER, LEFT, RIGHT, and FULL OUTER joins of two tables and would work with the examples Corion shows.