Hello, I am having a table structure like this:
Table : emp_details
id name value
1 phone 123-456-8765
1 address Toronto
1 age 25
1 sex male
1 firstname victor
Table:emp
id
1
2
3
4
.
.
.
I want the name value pair to be presented in a flat way:
I am doing it in this naive implementation:
select emp.id as id,emp1.value as phone,emp2.value as address,emp3.value as age,emp4.value as sex,emp5.value as firstname
from emp,
(select id, value from emp_details where name = 'phone') emp1 where emp1.id = emp.id,
(select id, value from emp_details where name = 'address') emp2 where emp2.id = emp.id,
(select id, value from emp_details where name = 'age') emp3 where emp3.id = emp.id,
(select id, value from emp_details where name = 'sex') emp4 where emp4.id = emp.id,
(select id, value from emp_details where name = 'firstname') emp5 where emp5.id = emp.id
and emp.id = 1
Could you please suggest a better way to do this?
Thank you very much!