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

  • SEARCH
  • Home
  • 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 8857253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:32:45+00:00 2026-06-14T14:32:45+00:00

I have trouble explaining my problem in words. so thats why my table examples:

  • 0

I have trouble explaining my problem in words. so thats why my table examples:

let say i want a result table like:

user_id |data_a |data_b
1       |hello  |world

and i need to extract it out of the table “dataset” in this form

data_id |user_id|data_type  |data_data
1       |1      |data_a     |hello
2       |1      |data_c     |xxx
3       |2      |data_a     |xxx
4       |1      |data_b     |world

I do somehting like

SELECT user_id , data_a, data_b
FROM dataset
WHERE ( data_type = data_a OR data_type = data_b )
AND user_id = 1

AND a = ( SELECT data_data WHERE data_type = data_a )
AND b = ( SELECT data_data WHERE data_type = data_b )

however it is not working. i know i am doing it wrong but i dont know how to do it and how it is called. I think a privot table but i am not sure
Thats why the description is so vague i hope someone understands.

  • 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-06-14T14:32:47+00:00Added an answer on June 14, 2026 at 2:32 pm

    This is basically a PIVOT but MySQL does not have a PIVOT function so you can replicate it using an aggregate function and a CASE statement. So your SQL will be something like this:

    select user_id,
      max(case when data_type = 'data_a' then data_data end) data_a,
      max(case when data_type = 'data_b' then data_data end) data_b
    from dataset
    group by user_id
    

    See SQL Fiddle with Demo

    Result:

    | USER_ID | DATA_A | DATA_B |
    -----------------------------
    |       1 |  hello |  world |
    |       2 |    xxx | (null) |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble doing this... You may want to get the same result as
I have trouble figuring out why a simple division like this one always returns
I have trouble shooting at file download problem. In Chrome, the download works fine.
I ran into a bug I have trouble explaining. Now that I found the
I have trouble getting the facet in my index. Basically I want to get
I'm having trouble explaining this but here it goes: I have a custom accordion
I feel like I'm way overthinking this problem, but here goes anyway... I have
I have trouble following the examples to get the callback. I have the following
We have trouble implementing a nice session mechanism in JSP. One of our requirement
I have trouble with strange behavior of for..in cycle in JavaScript. I have the

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.