Darlyn
Darlyn

Reputation: 4938

translating relational algebra to SQL

I have an database which i created relational algebra with. I have a task in relational algebra

  {ROOM*{PACIENT*{OPERATION(type='plastic')}}}[Room_ID]

which says "Select all rooms that have pacients that undertook operations in them" This "command" in relational algebra is correct. However i m not experienced in SQL so i have hard time translating it into SQL command. I know i can start like

SELECT * FROM ROOM
INNER JOIN

but how do i use multiple inner joins with sub agregate ( e.g between {} ) ?

I am trying to figure it out or find something about it but i am failing.

Upvotes: 0

Views: 406

Answers (1)

Uberzen1
Uberzen1

Reputation: 415

Without knowing the full schema it is impossible to say for sure, but it sounds like you want something like this:

SELECT DISTINCT r.Room_Id
FROM Room r
INNER JOIN Pacient p
    ON p.Room_Id = r.Room_Id -- Here put whatever the Foreign key linking these 2 tables is
INNER JOIN Operation o
    ON o.Pacient_Id = p.Pacient_Id -- Same here
WHERE [Type] = 'plastic'

Also, it may help to know what RDBMS you are using.

Upvotes: 0

Related Questions