+2 votes
in Databases by (73.6k 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

+1 vote
by (355k points)
selected by
 
Best answer

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

...