+1 vote
in Databases by (10.2k points)
When I combine the results of multiple queries into a single result using the UNION operator, I do not see duplicate records in the result. I need to keep the duplicate records in the query output, how to keep them?

1 Answer

0 votes
by (12.2k points)

If you want to keep duplicate records in the result, you need to use UNION ALL instead of UNION. By defaults, UNION operator removes all duplicate records.

E.g.

SELECT a,b,c FROM table1

UNION ALL

SELECT a,b,c FROM table2

Related questions

+3 votes
1 answer
+3 votes
1 answer
+2 votes
1 answer
+2 votes
1 answer
+3 votes
1 answer
...