Question

I'm not sure if the following two relations are compatible for a union:

R: <- schema name
B
1
2
2
3
3

And:

Q: -< schema name
A  B
5  1
6  1
4  2
3  4

I want to do the union: Q U R. Can I? What's the result?

Was it helpful?

Solution

The union operator requires that both relations are union-compatible. This means that they are required to have the same set of attributes. Note that this concept goes slightly beyond than sharing the same amount of attributes. This is because it also considers the content of the attribute.

This doesn't mean that both attributes should have the same name but rather that both attributes should, and I'm really walking away from relational algebra with this example, have a similar "data type". There is no such a thing in relation algebra but I think that if you have a programming background you'll easily get it by thinking on that concept.

EG: Consider the following relations:

  • Person(FirstName, LastName)
  • Country(Name, Population)

In this case, Person and Country are not union-compatible as they do not share the same set of attributes, even though they share the same amount of attributes.

OTHER TIPS

In fact, these two relations are not compatible for a union: they have a different number of attributes. Found the answer after some more research.

Two table are said to be union compatible if both the table have same number of attributes (column) and corresponding attributes have the same data type (int,char,float,date etc.). Corresponding attributes means first attributes of both relations, then second and so on.

union compatible:
A: (First_name (char), Last_name(char), Date_of_Birth(date))
B: (FName(char),LName(char),DOB(date))
Both table have 3 attributes and of same date type.

Not compatible:
A: (First_name (char), Last_name(char), Date_of_Birth(date))
B: (FName(char),LName(char),PhoneNumber(number))

(The third attributes are different.)

Check here for more detailed definition of Union Compatibility

In your case the two relations which you mentioned are not Union Compatibility because they do not have same number of attributes [schema R have one one attribute and schema Q have two attributes]
So you can not apply UNION operation on those schemas.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top