Understanding UNION and UNION ALL in SQL Server
A short look at the differences in UNION and UNION ALL in a SELECT query.
2025-04-07
4,234 reads
A short look at the differences in UNION and UNION ALL in a SELECT query.
2025-04-07
4,234 reads
Sometimes there is a need to combine data from multiple tables or views into one comprehensive dataset. This may be for like tables within the same database or maybe there is a need to combine like data across databases or even across servers. I have read about the UNION and UNION ALL commands, but how do these work and how do they differ?
2019-12-05
2018-06-12
1,059 reads
2016-11-15
1,313 reads
2016-05-31
1,591 reads
The use of union would seem to force a distinct in each of the select statements being unioned. The use multiple unions, with mixed union and union all clauses, seems to cause haphazard results.
2013-05-14 (first published: 2013-04-30)
926 reads
2012-03-08
2,809 reads
By Steve Jones
This value is something that I still hear today: our best work is done...
By gbargsley
Have you ever received the dreaded error from SQL Server that the TempDB log...
By Chris Yates
Artificial intelligence is no longer a distant concept. It is here, embedded in the...
A variety of food testing services, such as nutritional testing, water testing, milk testing,...
Comments posted to this topic are about the item Planning for tomorrow, today -...
We have a BI-application that connects to input tables on a SQL Server 2022...
I try to run this code on SQL Server 2022. All the objects exist in the database.
CREATE OR ALTER VIEW OrderShipping AS SELECT cl.CityNameID, cl.CityName, o.OrderID, o.Customer, o.OrderDate, o.CustomerID, o.cityId FROM dbo.CityList AS cl INNER JOIN dbo.[Order] AS o ON o.cityId = cl.CityNameID GO CREATE OR ALTER FUNCTION GetShipCityForOrder ( @OrderID INT ) RETURNS VARCHAR(50) WITH SCHEMABINDING AS BEGIN DECLARE @city VARCHAR(50); SELECT @city = os.CityName FROM dbo.OrderShipping AS os WHERE os.OrderID = @OrderID; RETURN @city; END; goWhat is the result? See possible answers