0

I have two tables, each one has 4 fields. A crc, a title, a parent and a parent_type.

The data in those tables represents files and to which entity they belong to.

A file with the same CRC can belong to multiple entities.

The first table represents a snapshot at one point in time, while the second table represents a snapshot at another point in time.

When a file is "moved" (think of it as a file system mv operation), the parent and/or the parent_type will change.

I want to get a list of the files that were moved between snapshot A and snapshot B.

This is what I currently have: http://sqlfiddle.com/#!5/89f0d4/1

Note that file 1 belongs to 2 different parents. file 4 was added/created. file 2 was moved from 2 GRUP to 3 GRUP. That is the one that I'm interested in.

alexandernst
  • 14,352
  • 22
  • 97
  • 197

1 Answers1

0

If I understand your question correctly what you need is to add a left join in the mix to exclude those who haven't changed...see below:

select a.*
  from memarxiu a
  join arxiu b
    on b.crc = a.crc
  left join (select *
               from arxiu) c
     on c.crc = a.crc
    and c.parent = a.parent
    and c.parent_type = a.parent_type
  where a.title = b.title
    and (a.parent <> b.parent
     or a.parent_type <> b.parent_type)
    and c.crc is null;
JuveLeo1906
  • 161
  • 5