SQL - Structured Query Language

SET Operators



SET operators are used to combine collection of queries results into a single result set. SQL join is used to combine collection of column(s) between two different tables with common associated column. Yet SET operator is used to combine collection of records among two or more tables. The number and the order of the columns must be the same in all SET operator queries and then data types must be compatible.

Note: For Demo, create Sales_Year_01 and Sales_Year_02 Tables and then INSERT sample records.

-- Example 38 --

 

USE EBusiness

GO

 

CREATE TABLE Sales_Year_01

(

Product_Code numeric(5)Primary Key,

Product_Name varchar(50) Not Null,

Sales_QTY numeric(7,2)

)

GO

 

CREATE TABLE Sales_Year_02

(

Product_Code numeric(5)Primary Key,

Product_Name varchar(50) Not Null,

Sales_QTY numeric(7,2)

)

GO

 

INSERT INTO Sales_Year_01 VALUES (101,'Product A', 127)

INSERT INTO Sales_Year_01 VALUES (102,'Product B', 167)

INSERT INTO Sales_Year_01 VALUES (103,'Product C', 185)

INSERT INTO Sales_Year_01 VALUES (104,'Product D', 1008)

 

INSERT INTO Sales_Year_02 VALUES (101,'Product A', 127)

INSERT INTO Sales_Year_02 VALUES (102,'Product B', 167)

INSERT INTO Sales_Year_02 VALUES (103,'Product C', 185)

INSERT INTO Sales_Year_02 VALUES (105,'Product E', 1008)


Query Output Screen



* * * * *


Email Your Comment To AUTHOR