in Databases retagged by
8,906 views
42 votes
42 votes

Consider the following SQL query

Select distinct $a_1, a_2, …, a_n$

from $r_1, r_2, …, r_m$

where P

For an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions?

  1. $\Pi_{a_1, a_2, … a_n}  \sigma_p \left(r_1 \times r_2 \times \dots \times r_m\right)$

  2. $\Pi_{a_1, a_2, … a_n}  \sigma_p \left(r_1 \bowtie r_2 \bowtie \dots \bowtie r_m \right)$

  3. $\Pi_{a_1, a_2, … a_n}  \sigma_p \left(r_1 \cup r_2 \cup \dots \cup r_m \right)$

  4. $\Pi_{a_1, a_2, … a_n}  \sigma_p \left(r_1 \cap r_2 \cap \dots \cap r_m \right)$

in Databases retagged by
8.9k views

4 Answers

49 votes
49 votes
Best answer
select distinct in SQL is equivalent to project and by default relation 1, relation 2 in SQL corresponds to cross-product. So, option A.
selected by
by

4 Comments

Why not union?? It will combine all tuples and return only those Which satisfy the condition!!
0
0

@vupadhayayx86

For cartesian product we don't check union compatability, but for performing union operation those tables must be union compatiable.

21
21
similarly  σ (R) is equivalent to select distinct * from R ?
0
0
13 votes
13 votes
Join intersection union might give lesser num of tuples cross gives all ,A option.
by

1 comment

I have doubt in option 1 and option 2? here why not option 2?
0
0
6 votes
6 votes
A. SQL form the cartesian product of the relation named in the form clause, perform a relational algebra selection using the where clause predicate and then projects the result onto the attributes of select clause.
3 votes
3 votes

SELECT DISTINCT In SQL  -  Projection (Π) in Relational Algebra

FROM in SQL - Cartesian Product (×) in Relational Algebra

WHERE in SQL - SELECTION(σ) in Relational Algebra

So, the query will be equivalent to 

Πₐ₁,ₐ₂,…ₐₙσₚ₍ᵣ₁×ᵣ₂×⋯×ᵣₘ₎

 

edited by
Answer:

Related questions