0

I need to do a specific operation on two tables which is:

(A - B) U (B)

B has duplicate values and A does not have any duplicate values.

In the final union I want to have the duplicate values of B as well. So basically I want to combine both A and B and preserve duplicate values of B in final table

How can we do this in SQL? I tried

A EXCEPT B UNION B

but it failed

2
  • 1
    UNION removes duplicates, while UNION ALL does not.
    – mustaccio
    Nov 22, 2021 at 12:55
  • Instead of tagging multiple database systems, please only tag the one you're actually using, as the answer can be dependent and vary on this.
    – J.D.
    Nov 22, 2021 at 13:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.