Hello Sirs/Mams,
A pleasant day to every one.
I have the following tables and a sample data:
--------------------------------------------------------
PERSON table:
person_id first_name last_name
1 PETER PARKER
2 BRUCE BANNER
3 TONY STARK
--------------------------------------------------------
STUDENT table:
person_id student_number
1 STUD-001
--------------------------------------------------------
FACULTY table:
person_id faculty_number
2 FACT-001
--------------------------------------------------------
EMPLOYEE table:
person_id employee_number
3 EMPL-001
--------------------------------------------------------
The person_id in PERSON table is a primary key and the three person_id in STUDENT, FACULTY, EMPLOYEE are foreign keys respectively.
How can I combine the student_number, faculty_number and employee_number columns into ONE column and give it a new name, say ID? This is the expected output:
id first_name last_name
STUD-001 PETER PARKER
FACT-001 BRUCE BANNER
EMPL-001 TONY STARK
I tried a lot of combinations but it seems I can not get it right.
I hope some one could help me construct a SQL statement/stored procedure on how to achieve this.
Thank you and more power!
Warm regards,
Mark Squall