I have such TABLE with data:
A | B | C | D | E
-----------------------
a1 | b1 | c1 | d1 | PA
a1 | b1 | c1 | d1 | PR
a2 | b2 | c2 | d2 | PA
a3 | b3 | c3 | d3 | PA
a3 | b3 | c3 | d3 | PR
- row1 has its counterpart row2 (they are only different by col E)
- row3 has no counterpart - unique
- row4 has its counterpart row5 ( same as first statement - col E )
the query should gave me a result like this:
A | B | C | D | E
-----------------------
a2 | b2 | c2 | d2 | PA
only unique row which has no counterpart - no row with same set of data only which different only by value in column E
- we can apply here a few approaches which one will be most effective if we have more rows with its counterparts as unique rows (without counterpart)
- which join use ?
- which one created select statement subtract or add ?
ps. an extended case
A | B | C | D | E
----------------------------------------
a1 | b1 | c1 | 2017-05-16 11:46:36 | PA
a1 | b1 | c1 | 2017-05-16 11:46:37 | PR
a2 | b2 | c2 | 2017-05-17 01:34:28 | PA
a3 | null | c3 | 2017-05-12 19:14:15 | PA
a3 | b3 | c3 | 2017-05-12 19:14:15 | PR
a4 | b4 | c4 | 2017-05-12 19:16:15 | PA
a4 | b4 | c4 | 2017-05-12 23:16:15 | PR
- column A -D may contain null values (row4)
- column D is a TIMESTAMP and it could vary from its counterpart by 1-2minutes (row1, row2)
- we add the max difference in timestamp = example 2 minutes (row6 has no counterpart as row7 vs row6 timestamp difference is greeter than 2 minuts (4 hours)
- we don't want any row with PR in our result
expected result:
A | B | C | D | E
----------------------------------------
a2 | b2 | c2 | 2017-05-17 01:34:28 | PA
a4 | b4 | c4 | 2017-05-12 19:16:15 | PA