/  Technology   /  Union Operation ( U ) in Python

Union Operation ( U ) in Python

 

The ‘Union’ operation combines two relations without having duplicates.

 

Let us understand the UNION operation better using some examples.

Consider the following table: 

R1 :    FACULTY-1

FNoFNameDNoQualSalary
22Riya21Ph.D55000
24Priya22M. Tech50000
25Zayn22M. Tech42000
27Harry23M. Tech28000
30Sia23M. Tech32000
33Max24Ph.D53000
35Fred24Ph.D52000
37Diva25M. Tech26000
39Ben25M. Tech24000
40Trent25M. Tech34000

 

Example-1 :  Find the tuples of Dno = 23 or tuples of DNo = 25.

  sDNo = 23  (Faculty-1)  U sDNo = 25  (Faculty-1)

Output :                           

FNoFNameDNoQualSalary
27Harry23M. Tech28000
30Sia23M. Tech32000
37Diva25M. Tech26000
39Ben25M. Tech24000
40Trent25M. Tech34000

 

Example-2 :  Find the FNames of Dno = 22 or FNames of DNo = 24.

P FName (sDNo = 22(Faculty-1) ) U P FName (sDNo = 24(Faculty-1) )

 

 Output :                                       

FName
Priya
Zayn
Max
Fred

 

Note : Here, the FNames from both DNos 22 and 24 are taken.

 

 

Leave a comment