1

I have a table A like this:

   id   field      value
----------------------
   1845  name       john
   1845  post       manager
   1845  birth      1980
   1846  name       alex
   1846  post       employee
   1846  birth      1986

i want a result set that look like this:

     id     name     post     birth
----------------------------------------
    1845    john    manager   1980
    1846    alex    employee  1986
.
.
.

is there any way in oracle to do this?

1 Answer 1

2

Assuming that ID field will have the same number for a given name, post and birth, the following query might help you.

select 
  distinct 
  id,
  (select value from test where id = a.id and field = 'name') as name,
  (select value from test where id = a.id and field = 'post') as post,
  (select value from test where id = a.id and field = 'birth') as birth
from test a

Note that the above query will not work for the case below where there are 2 names for the same ID:

id   field      value
----------------------
1845  name       john
1845  post       manager
1845  birth      1980
1845  name       alex
1845  post       employee
1845  birth      1986

Example: http://sqlfiddle.com/#!4/ca93f/3

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.