Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting DISTINCT rows in relational algebra

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?

like image 347
Karan Avatar asked Jan 23 '11 18:01

Karan


People also ask

How do you use distinct in relational algebra?

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.

Does SELECT in relational algebra remove duplicates?

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.

Does SELECT distinct apply to all columns?

Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.

Are there duplicates in relational algebra?

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.


1 Answers

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.

like image 196
nvogel Avatar answered Sep 17 '22 14:09

nvogel