I would like a query that would show the most complete matching records as below. I am using MS Access though an ANSI SQL or Oracle answer would be ok if no access solution.
- col2 is the only non-nullable column, but as you can see by the result, there may be several records with same value in col2 returned
- As you can see, nulls are ignored in coalescing records together to make result.
Table1
col1 col2 col3 col4
---------------------------------
c d g
c d
d g
d e g
d e
e g
e e g
e e
e g
e f
g h
Result of query
col1 col2 col3 col4
---------------------------------
c d g
d e g
e e g
e f
g h
I thank you for trying but after further investigation, I found a bug with both proposed solutions using "join" and "not exists".
bug in proposed "join" solution There is a bug as shown below where two rows became 4 in the proposed
col1 col2 col3 col4
d g i d h j
result of query
col1 col2 col3 col4
d g i d g j d h i d h j
bug in proposed "not exists" solution
After fixing the query by adding a closing parentheses I was able to run the "not exists" solution. Two rows that match on col2 but don't match on col3 are combined into one row. They have different data and should be unique
col1 col2 col3 col4 --------------------------------- d g i d h result of query col1 col2 col3 col4 --------------------------------- d g i