One INSERT with UNIONS or multiple INSERTS?

Viewed 15689

I have a sql function that returns a table. The table is populated via 6 or so reasonably complex statements.

Is it better to UNION together these statement so there is only 1 insert or are these better kept separate?

Or does it make no difference whatsoever?

6 Answers

UNION v/s UNION ALL are not functionally same. Exercise caution when using UNION as it will try to de-dup and potentially that may not be the result you're originally looking for.

Regarding the question, multiple INSERT(s) might be faster given the lesser number of records compared to UNION ALL

Related