JRW2252
JRW2252

Reputation: 83

Query Multiple Columns Within a Table

I have a table of employees that are formatted as follows:

EMPLOYEE (FNAME,MINIT,LNAME,SSN(PK),BDATE,SUPERSSN(NULLABLE))

I need to query every employee and retrieve the following information:

FNAME(employee),LNAME(employee),SUPERSSN,(super)FNAME,(super)LNAME

UPDATED

After running this query:

SELECT A.FNAME,A.LNAME,A.SUPERSSN,B.FNAME,B.LNAME 
FROM EMPLOYEE 
A LEFT JOIN EMPLOYEE B 
ON A.SUPERSSN = B.SSN;

The results were close, but when the superssn was null (CEO/Boss) it caused the remaining rows to populate as null also and did not populate with the actual supervisors ssn. I'm trying to use an IF statement to fix the problem with having a SuperSSN that is null, but I'm receiving the error: ORA-00905: missing keyword.

Below is the query that I ran that generated the error.

SELECT A.FNAME,A.LNAME,A.SUPERSSN,B.FNAME,B.LNAME 
FROM EMPLOYEE A LEFT IF A.SUPERSSN <> 'NULL'
JOIN EMPLOYEE B ON A.SUPERSSN = B.SSN;

Upvotes: 0

Views: 205

Answers (1)

ajay gandhi
ajay gandhi

Reputation: 563

Select A.FName, 
       A.LNAme, 
       A.SuperSSN, 
       B.FName, 
       B.LName 
from Employee A 
Left Join Employee B
          On A.SuperSSN = B.SSN

Upvotes: 1

Related Questions