taway0282
taway0282

Reputation: 197

Is having union in σ the same as having two queries?

I have this question:

What are the names of Employees in Boston or Chicago?

With these relations:

employees(id, name) and workIn(id, city)

Where the id in both relations refer to the same thing (the id of the employee)

The query I wrote was:

Π name (σ city="Boston" U city="Chicago"(employees ⋈ workIn))

The solution given to the question was:

Π name (σ city="Boston"(employees ⋈ workIn)) U
Π name (σ city="Chicago"(employees ⋈ workIn))

Would the two queries return the same result? Or is my query just wrong?

If my query is wrong, what would the difference be in values returned?

Upvotes: 0

Views: 48

Answers (1)

Renzo
Renzo

Reputation: 27424

Your query is wrong since you are using the Union operator (U) between two logical conditions city="Boston" U city="Chicago" (which does not make sense, since the Union is a set operator, not a logical operator).

The logical operator to use in a condition is the “or” (written ), which makes a compound condition true when either of the two components are true (or both are true, but this is not possible here).

So a correct expression is:

Π name (σ city="Boston" ∨ city="Chicago"(employees ⋈ workIn))

and this is equivalent to the expression with the Union:

Π name (σ city="Boston"(employees ⋈ workIn)) U
Π name (σ city="Chicago"(employees ⋈ workIn))

Upvotes: 2

Related Questions