SQL Server set operation set operation allows us combine or select common data from more 2 tables/ queries. If you want to get data from more than two tables then you will have to repeat set operator between each query. There are basically 3 types of set operations like Union Union all (special case A + B) Intersection Except (Minus) For demo we will use the below query to create a table and use it throughout out examples CREATE TABLE Product1 (ProductID INT, ProductName VARCHAR(15)) CREATE TABLE Product2 (ProductID INT, ProductName VARCHAR(15)) INSERT INTO Product1 VALUES (1,'Pen'),(3,'Notebook'),(4,'Pin'),(6,'Punch'),(7,'Glue') INSERT INTO Product2 VALUES (1,'Pen'),(2,'Stapler'),(4,'Pin'),(8,'Book'),(9,'Glitter') UNION union allows us to combine data from two different queries/tables. If the data is common between 1st and 2nd query then it gives distinct data. The output of union is sorted. A = {1,...
The blog includes article on Datawarehousing, Business Intelligence, SQL Server, PowerBI, Python, BigData, Spark, Databricks, DataScience, .Net etc.