Choc Boo, welcome to stackoverflow [relational-algebra]. I strongly suggest you find yourself a textbook or online learning resource that will take you step-by-step -- preferably something you can share with other learners.
Are you sure it's RA you want to learn? Or SQL? They're very different: as a noob, learning one will probably completely confuse you wrt the other. (The connection between them won't become clear until you're much deeper in.)
There are places you can run RA online. But beware they use a specific dialect of RA, which might not be the one you're trying to learn.
Your query could perhaps be expressed as:
"Return all Name
s that appear in a single tuple."
Note I didn't mention "only doing 1 subject": a relation is a set; if any Name
appears more than once it must be that it appears with multiple Subject
s.
There's a 'quick and dirty' way to an answer: for each Name
count how many tuples; restrict the result to return only those with count == 1. (That way will need using an advanced RA operator for counting.)
There's a longer-winded way that uses only more primitive operators: take two versions of your relation; pair each tuple with each from the other version; the Name
s that appear in more than one tuple will pair up in multiple ways same-Name
-different-Subject
; those are the Name
s you don't want.
What do I mean by "two versions"? Find out about the Rename operation (ρ
). What do I mean by "pair ... with ..."? Find out about the Join operation (⋈
). What do I mean by "don't want"? Find out about the set difference operator (-
): I said relations are sets.