Question

SELECT * FROM Schools JOIN Masts on Schools.City = Masts.City

becomes:

Schools ⋊ Masts = σSchools.city = masts.city SCHOOLS X MASTS

Am i correct with this? hopefully someones around for a quick answer in the next 20 mins or so.

Was it helpful?

Solution

If you don't have a copy of this book: Applied Mathematics for Database Professionals, you really ought to check it out. It helped me immensely with these kinds of problems. (The hardcover is a real find, but there's only one copy and it's way too expensive—but there are soft-cover versions and the e-book format available, too.)

Also, check out this very good Wikipedia article on Relational Algebra.

The Wikipedia article above shows that what you're trying to accomplish is called an equijoin, which is a specialized form of θ-join. Using your example above, you should have output the following:

Let:

  • Schools → S;
  • Masts → M
  • θ → =

Then:

S ⨝θ M → σθ(S × M)

In the book Applied Mathematics for Database Professionals, the authors use "lower-level" relational algebra to define a SQL JOIN. The definition follows:

Let:

  • Schools → S
  • Masts → M

Then:

{ s ∪ m | s∈S ∧ m∈M ∧ s(City) = m(City) }

The authors further go on to give a general definition of the above using the operator ⊗ (perhaps it was easier for them to publish that symbol rather than using the traditional ⨝ symbol— doesn't make sense though, as they did use Latex—but I'll stick with the traditional symbol):

R ⨝θ T → { r ∪ t | r∈R ∧ t∈T ∧ "r and t are compatible" }

Compatibility is "user-defined", hence ⨝θ. θ could be any relational operator, <, >, etc.When testing for two attributes being equal as being the result of a successful join condition, then θ → =, and as stated previously, this is a specialized θ-join known as an equijoin.

So, after all that:

R ⨝θ T → σθ(R × T) → { r ∪ t | r∈R ∧ t∈T ∧ "r and t are compatible" }

I know this is much later than 20 minutes from when you posted, but hopefully someone finds it helpful.

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