I want to convert a sql query to relational algebra containing exist keyword

492 Views Asked by At
select fname,lname,salary from employee where exists
(select essn from dependent where employee.sex = dependent.sex); 

this is the query

1

There are 1 best solutions below

0
AntC On

Nicer SQL, avoiding exists:

select distinct fname,lname,salary from employee
                                 join dependent on employee.sex = dependent.sex;

Nicer nicer SQL, but only works if sex is the only column in common between tables employee, dependent

select distinct fname,lname,salary from employee
                                 natural join dependent;

Relational Algebra Appendix A style (with the same proviso)

(employee JOIN dependent) {fname,lname,salary}

Relational Algebra Codd 1972 style (with the same proviso)

π<fname,lname,salary>(employee ⋈ dependent)
  • (putting the attribute names in < >, because subscripting doesn't work in SO's code.)