I have a table that looks like this:
ID Subid Time Value Value2
1 1 3 100 2
1 1 4 100 2
2 2 3 200 1
2 2 4 200 2
4 4 4 10 4
5 6 3 10 2
5 6 4 12 2
What i want to do now is just show the entries where there is a difference from time 3 to time 4. So the result should look like this:
ID Subid Time Value Value2
2 2 3 200 1
2 2 4 200 2
4 4 4 10 4
5 6 3 10 2
5 6 4 12 2
Conditions for an entry being in the second part are as follows: If there are two entries with the same ID and Subid, but a different month then check if value and value2 are equal. If these are BOTH equal, then remove the entry, else show the entry. If no match can be found in the other time then also show the entry. Typically this table would have a lot of entries that match, so I want to make my life easier by sorting those out.
I have to use MS Access (2010) to do this.
Thank you for your help.
EDIT after Remou's answer:
I now have the problem that I do not really have the table shown above, but that I create it with another query. So for now I just put the query to create that table in the four places Remou uses it... I'm sure there is a better way to do this, but I can't figure it out...
SELECT t2.*
FROM (SELECT t.ID, t.SubID, t.Time, t.Value, t.value2, t.value FROM
( HUGE SELECT HERE with 3 joins) t
WHERE t.Time=4) AS t2
LEFT JOIN
(SELECT t.ID, t.SubID, t.Time, t.Value, t.value2, t.value
FROM
( HUGE SELECT HERE with 3 joins) t
WHERE t.Time=3) AS t1
ON t2.Id = t1.Id
WHERE t2.value<>t1.value
OR t2.value2<>t1.value2
OR t1.Id Is Null
UNION ALL
SELECT t1.* FROM
(SELECT t.ID, t.SubID, t.Time, t.Value, t.value2, t.value
FROM
( HUGE SELECT HERE with 3 joins) t
WHERE t.Time=3) AS t1
LEFT JOIN
(SELECT t.ID, t.SubID, t.Time, t.Value, t.value2, t.value
FROM
( HUGE SELECT HERE with 3 joins) t
WHERE t.Time=4) AS t2
ON t1.Id=t2.Id
WHERE t1.value<>t2.value
OR t1.value2<>t2.value2
OR t2.Id Is Null
ORDER BY Id, EntryNo;