# Relational DB :Relation-type Algebra?

Tags:
1. Oct 10, 2015

### WWGD

Hi, say we have entities A,B,C in a Relational Database. Is there a sort-of operational algebra that allows us to determine that if, say, A and B are in a many-many relation and B and C are in a 1-many relation, then A,C are in a certain relationship, i.e., a composition algebra between relations (whenever "composable", of course)? And, while we are at it, when are relations "composable" (in a formal way, ignoring semantic issues of whether the composition is meaningful) , meaning if A is related to B and B to C, can we say A is related to C? Any Mathematical Analogies more than welcome.
Thanks.

2. Oct 10, 2015

### andrewkirk

If it's any help, the set-theoretic definition of an SQL join of two tables is the subset of all elements of the Cartesian product of those two tables that satisfies the specified join condition.

If we consider each table $T$ to be a function $f_T:\mathbb{N}\times col.names(T)\to U$ where $U$ is the set of all possible values in all allowed data types, such that $f(n,\alpha)$ is the value in row $n$, column $\alpha$ of table $T$ then we can write an inner join on column $\alpha$ of tables $A$ and $B$ as

$$InnerJoin(A,B,\alpha)=\{(a_i,b_j)\in A\times B\ |\ f_A(i,\alpha)=f_B(j,\alpha)\}$$

This is readily extendable to outer joins and other types of joins, and to joins of more than two tables.

It's not an algebraic construct yet, as no group or similar operation has been defined, but at least it gives a set-theoretic foundation on which one might be able to do so

3. Oct 12, 2015

### QuantumQuest

You're talking about relational algebra i.e. basically operations on sets. So, in relational databases operations are operations on some kind of sets and we have the usual operations of projection, selection, join etc. If you don't know much about these, a good start is Wikipedia's page about Relational Algebra

4. Oct 12, 2015

### WWGD

I think I understand them pretty well, but I dont see how referring every question to set operations clarifies things in here. Seems like understanding computer programs in terms of logical operators and switches.

Last edited: Oct 13, 2015
5. Oct 13, 2015

### WWGD

@QuantumQuest : Of course you are correct, it is just too time-consuming to try to answer things at the most fundamental level, however interesting and illuminating it often is to do so. Time limitations make this approach impractical , despite allowing for a solution.

And, I guess that at the end of the day, relations are closed under composition. I make an effort not to be a hack, but sometimes I just hope to get an answer that works even without fully understanding it. It is just too time- and energy- consuming to follow this approach all the time.