![]() The union is different from the join that the join combines columns of multiple tables while the union combines rows of the tables. The following picture illustrates A UNION B:Īnd the following picture illustrates A UNION ALL B Query to UNION results into temporary table. An example of UNIONing the results from sys.dmexecquerystats and sys.dmexecquerystats into a temporary table is provided in listing 1.-Listing 1. The INTO for the SELECT INTO goes into the first query of the set. Suppose, we have two result sets A(1,2) and B(2,3). This is actually a pretty simple thing to do. To retain the duplicate rows in the result set, you use the UNION ALL operator. To eliminate the duplicate rows, the database system sorts the combined result set by every column and scans it for the matching rows located next to one another. ![]() ![]() Then, it combines two individual result sets into one and eliminates duplicate rows. The database system processes the query by executing two SELECT statements first. The columns returned by the SELECT statements must have the same or convertible data type, size, and be the same order. To use the UNION operator, you write the dividual SELECT statements and join them by the keyword UNION. Table2 Code language: SQL (Structured Query Language) ( sql )
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |