in Databases edited by
3,741 views
16 votes
16 votes
Consider a relation examinee (regno, name, score), where regno is the primary key to score is a real number.

Write a relational algebra using $( \Pi, \sigma, \rho, \times)$ to find the list of names which appear more than once in examinee.
in Databases edited by
3.7k views

3 Comments

Can anyone please post SQL query for this?
0
0

equivalent SQL query :-

select e1.name

from examine e1

where exist ( select *

              from examine e2

              where e1.regno ≠ e2.regno and e1.name = e2.name );
6
6
Thank you
0
0

2 Answers

20 votes
20 votes
Best answer
$\pi_{\text{exm1.name}}(σ_{(\text{exm1.regno} \neq \text{examinee.regno}) \wedge (\text{emp1.name} = \text{emp2.name}) })(ρ _{\text{exm1}}(\text{examinee}) \times  \text{examinee}) $
edited by

4 Comments

@Devesh_Kumar

The query is designed only to select the tuples where registration numbers are not same, but name is same.

So, it'll obviously give correct result for two different persons with same name.

0
0
What is emp1 and emp2 in ur answer
1
1

Hi @Ayush Upadhyaya@Shaik Masthan
How above RA will ensure that two person having same name appear more than once in examination?

0
0
1 vote
1 vote

1) $\Pi_{name}\left ( \sigma _{count(cnt)>1}\left ( _{name}g_{count(regno)\ as \ cnt}\left ( examinee \right ) \right ) \right )$

2) $SELECT_{regno}FROM\;examinee\; HAVING\;(score>avg(score))$

$\Pi _{regno}\left ( \sigma _{score>avg(score)}\left ( examinee \right ) \right )$

3) $SELECT_{centr\_code}FROM\;examinee\;join\;appears WHERE\;(score>80)$

$\Pi _{center\_code}\left ( \sigma _{score>80}\left ( examinee\Join appears \right ) \right )$

edited by

4 Comments

Having can't be used without group by, this way in the second query.
4
4

@Sheshang 

I dont think so standard relational algebra allows aggregate functions.

0
0

2.

 

​​​​​​

3
3

Related questions