The above condition need to satisfy for different conditions like"MASTER", "JUNIOR". etc..All these conditions needs to be satisfied in a single output column. So in my output the distinct records will be "STUD","MASTER", "JUNIOR","NA".
You need to think about how you are comparing your values. Looking at your code (which should be erroring by the way because of the "=" operator) you are trying to compare memory rather than values. Take a look at this web page which will explain it thoroughly...