MS Sql Server | Union vs Union ALL
One way you can do it is using UNION, but I recommend UNION ALL here. \nThe major difference between UNION and UNION ALL is that UNION gets rid of duplicate rec
One way you can do it is using UNION, but I recommend UNION ALL here. \nThe major difference between UNION and UNION ALL is that **UNION gets rid of duplicate records** whereas **UNION ALL takes all the records**. \n\nIn our scenario, there won\'t be a situation where we are going to have duplicate records so using UNION and forcing the server to check for duplicates will be an extra overhead and will increase execution time.\n\nHere\'s my script for the UNION ALL\n\n```\nSELECT \n    product_id, \n    \'store1\' as store, \n    store1 as price\nfrom Products\nwhere store1 is not null\n\nUNION ALL\n\nSELECT \n    product_id, \n    \'store2\' as store, \n    store2 as price\nfrom Products\nwhere store2 is not null\n\nUNION ALL\n\nSELECT \n    product_id, \n    \'store3\' as store, \n    store3 as price\nfrom Products\nwhere store3 is not null\n```
['Union Find', 'MS SQL Server']