Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1075343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:15:31+00:00 2026-05-16T21:15:31+00:00

I am having a table structure like this: Table : emp_details id name value

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:15:32+00:00Added an answer on May 16, 2026 at 9:15 pm

    I believe you are looking for table rotation

        SELECT CASE [d.name]
                 WHEN 'phone' THEN [d.value]
                 ELSE ''
               END AS phone,
               CASE [d.name]
                 WHEN 'address' THEN [d.value]
                 ELSE ''
               END AS address,
               CASE [d.name]
                 WHEN 'age' THEN [d.value]
                 ELSE ''
               END AS age,
               CASE [d.name]
                 WHEN 'sex' THEN [d.value]
                 ELSE ''
               END AS sex,
               CASE [d.name]
                 WHEN 'firstname' THEN [d.value]
                 ELSE ''
               END AS firstname
        FROM   emp_details d
               INNER JOIN emp e
                 ON d.id = e.id
        WHERE  e.id = 1 
    

    And here is anothere way

    SELECT phone = Isnull((SELECT [value]
                           FROM   emp_details
                           WHERE  [name] = 'phone'
                                  AND [id] = d.[id]),''),
           address = Isnull((SELECT [value]
                             FROM   emp_details
                             WHERE  [name] = 'address'
                                    AND [id] = d.[id]),''),
           age = Isnull((SELECT [value]
                         FROM   emp_details
                         WHERE  [name] = 'age'
                                AND [id] = d.[id]),''),
           sex = Isnull((SELECT [value]
                         FROM   emp_details
                         WHERE  [name] = 'sex'
                                AND [id] = d.[id]),''),
           firstname = Isnull((SELECT [value]
                               FROM   emp_details
                               WHERE  [name] = 'firstname'
                                      AND [id] = d.[id]),'')
    FROM   emp_details d
           INNER JOIN emp e
             ON d.id = e.id
    WHERE  e.id = 1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am having table structure like this table1 table2 pid pname pid uid cat
I'm having difficulty with this problem. I have a table with this structure: OrderID
I am having two tables like this.Both are separate tables AccountNo User Name ----------------------------------
I have a table structure having a EMP_DATE column as below ID EMP_DATE ----
I have DB2 table having following structure CREATE TABLE DUMMY ( ID CHARACTER(10) NOT
I have a table with below structure. I am not having control over changing
I am having a table called Tl which consists of fields ID,Name and Course.
Hai I am having the table USERS with the fields like USERACCNO FIELD-1 FIELD-2
I'm having doubts about my table structure, and I wonder if there is a
When retrieving a lookup code value from a table, some folks do this... Dim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.