I'm new to sql, if I run this projection on a table, would it return nothing or an error of this projection is not allowed (syntax)? I put all infos of the table and the projection in this picture below to make it easier to read :)
Asked
Active
Viewed 75 times
3
-
SQL & relational algebra are two different things. Also, what *reference* were you given for (your version of) 'relational algebra'? Whate *definition* were you given for projection? PS Please use text not images whenever possible, like for this question. (You can google 'unicode pi' etc if you want a symbol.) – philipxy May 26 '17 at 08:57
1 Answers
1
In relational algebra, your set difference would yield an error because the two sets are not union-compatible:
For set union and set difference, the two relations involved must be union-compatible—that is, the two relations must have the same set of attributes. from wikipedia
In SQL, the set difference would work, because union compatibility is understood in a more lenient way, i.e. the tuple degrees and data types must match, but not the names. So this is valid SQL:
SELECT X FROM A
EXCEPT
SELECT Z FROM A
The result would be a table with a single column named X
However, even in SQL, you couldn't project Y
from the set difference, so πY is not possible, neither in SQL nor in relational algebra. This would be invalid SQL:
SELECT Y -- Y is not defined here, only X
FROM (
SELECT X FROM A
EXCEPT
SELECT Z FROM A
)

Lukas Eder
- 211,314
- 129
- 689
- 1,509