In the database,UnionAndUnion allThe keywords combine the two results into one, but the two are different in terms of usage and efficiency.
UnionDuplicate records are filtered out after the table link is established. Therefore, after the table link is established, the generated result set is sorted, and duplicate records are deleted before the results are returned.
In most applications, duplicate records are not generated. The most common is Process Tables and historical tables.Union. For example:
Select * From gc_dfys
Union
Select * From ls_jg_dfys
ThisSQLWhen running, the results of two tables are first taken out, and then sorted by space to delete duplicate records. Finally, the result set is returned. If the table has a large amount of data, it may be sorted by disk.
WhileUnion allSimply merge the two results and then return them. In this way, if duplicate data exists in the two returned result sets, the returned result sets will contain duplicate data.
In terms of efficiency,Union allAspect RatioUnionTherefore, if you can confirm that the merged two result sets do not contain duplicate data, you can useUnion all, As follows:
Select * From gc_dfys
Union all
Select * From ls_jg_dfys
Author's blog:Http://blog.csdn.net/sunlen/