Skip to content
Advertisement

get relation data from one table in oracle [closed]

I have a table, let’s called it data_employee. It contains:

and the data is:

I want to query username’s superior, which is:

I’ve tried subquery but sometimes they return multiple data, because I have sub group head

and the data also written group head

so, for an example: the result is:

when I want to find john_doe’s department head, the result is smith_jaeger

Advertisement

Answer

Consider this query:

The first criteria is before the or, the second criteria is after the or. In the first criteria it’s important to specify that an employee is department head and the other is not to avoid having results saying that the department head is his/her own boss. With the second criteria we did not exclude duplicates, because if there could be separate departments with the same division (which should not be the case, but we cannot exclude inconsistency, especially if these are textual data), then the multiple bosses of the separate departments of the same division will appear in the results. Also, if there are multiple department heads, that’s a problem as well.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement