There is a DISTINCT operator in SQL. However, I have an assignment in which I need to get some distinct values from a table, and I can only use relational algebra. Is there a way?
The projection in relational algebra is equivalent to select distinct. In select statement of sql, duplicates are allowed as it is based on multiset theory but in projection of relational algebra, which is based on set theory, duplicates are not allowed.
A relation is a set and so it has no duplicates. This means that selection eliminates duplicates. However, note that database systems that represent relations as tables may not eliminate duplicate rows.
Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.
As Martin suggested, Relational Algebra deals with sets, projection, selection, union, intersection are all SET operations. And sets don't have duplicates. However real world systems take into considerations tuples or multisets, which can have duplicates.
Relational projections always return distinct tuples so DISTINCT is never needed. Duplicate tuples are not permitted in the RA - that being one major difference between the relational model and the SQL model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With