Question

I am trying to write the following query using the relational algebra:

"Find the names of sailors who reserved a red or a green boat"

Here is my solution: enter image description here

But the book gives the following solution: enter image description here

And another equivalent solution given by book: enter image description here

End here is the related tables: enter image description here

My question is, can't we use the "or" symbol (V) in selection operator? Is my solution wrong? Why do we need renaming operator?

Thanks

Was it helpful?

Solution

Yet more proof that there is no such thing as "the" relational algebra.

As for restriction :

Your book/teacher seems to go by the principle that restriction conditions can only be "very basic". In the sense as the wiki article on http://en.wikipedia.org/wiki/Selection_%28relational_algebra%29 (at least one attribute referenced, one other attribute or constant value, only one single comparison operator involved, no other operator invocations allowed such as SIN(angle attr) or MONTH(datetime attr) or ...).

But that restriction (on the restrict condition) is unnecessary. The wiki article about relational algebra on http://en.wikipedia.org/wiki/Relational_algebra#Selection_.28.CF.83.29 says explicitly "... is a propositional formula that consists of ... and the logical operators AND,OR,NOT ...".

As for rename :

The RENAME operator in relational algebra is used to yield a relation value that differs from the input only in that certain attributes have "changed name".

Your book/teacher apparently uses an operator called "rename" to assign a name to some specified relational expression (a UNION in your example). That isn't even an algebraic operation !!!

(While it is a valid and useful idea in language design to devise a possibility for the user to have "named expressions", that he can subsequently reference using just the assigned name, this is a matter of language design, not of relational algebra !)

OTHER TIPS

I tested this code, in my phpmyadmin and it must be work

Select all sailors who reserves, while the boats already created;

SELECT * FROM sailors INNER JOIN reserves ON reserves.sid = sailors.sid LEFT JOIN boats ON reserves.bid = boats.bid

Specific Selection(Color:Red);

using WHERE color = 'red'

SELECT * FROM sailors INNER JOIN reserves ON reserves.sid = sailors.sid LEFT JOIN boats ON reserves.bid = boats.bid WHERE color = 'red'

Multi Selection(Color:Red and Blue);

using WHERE color = 'red' or 'blue'

SELECT * FROM sailors INNER JOIN reserves ON reserves.sid = sailors.sid LEFT JOIN boats ON reserves.bid = boats.bid WHERE color = 'red' or 'blue'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top