The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+18 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)$

asked in Databases by Veteran (59.5k points)
retagged by | 1.4k views

3 Answers

+25 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.
answered by Veteran (355k points)
selected by
If query doesn't ask for distinct,is there any valid relational algebra expression for it?
@prayas No

RA: Uses set

SQL: Uses Multiset
Sir can you please explain why option B is not correct?
Option B is doing natural join meaning only those tuples having same value for common attribute(s) in both the relations are selected for output.
Oh it.Thank you sir
+9 votes
Join intersection union might give lesser num of tuples cross gives all ,A option.
answered by Active (3.3k points)
I have doubt in option 1 and option 2? here why not option 2?
+4 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.
answered by Active (1.6k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

38,058 questions
45,554 answers
48,918 users