![]() ![]() Suppose you were asked to provide a list of all AdventureWorks product categories and subcategories. Note the ORDER BY clause applies to the combined result. For instance, if you have two tables, Vendor, and Customer, and you want a combined list of names, you can easily do so using: SELECT ‘Vendor’, V.Name SQL UNION for sorting results from two separate queries as one combined result. Use UNION to return a distinct list of values. The Union operator returns rows from both tables. ![]() Learn More: What is the Difference Between a Join and a Union > Combine Table Rows Using SQL UNION If you want to keep all rows from both select statement’s results use the ALL keyword. When rows are combined duplicate rows are eliminated. The columns, in order, must be of the same data type.The number of columns must be the same for both select statements.In order to union two tables there are a couple of requirements: In SQL this statement looks like SELECT columnlist Here is an illustration of what a SQL UNION looks like ![]() Unlike a join, which combines columns from different tables, a union combines rows from different tables. You can use the UNION clause to combine table rows from two different queries into one result. In this section let’s talk about the SQL UNION operator. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |