3

I'm quite new on data bases and would be very grateful for some help, I have a database on the following format:

ID     Nbr     Data1     Data2    Data3
1      1       a    
2      1                 b
3      1                          c
4      2       d    
5      2                 e
6      2                          f

And would like to have a way to extract, with a MySQL query, the data on the following format:

Nbr     Data1     Data2    Data3
1       a         b        c
2       d         e        f

I know that is not best practice to have the data on a non normalized format but sadly I can't change the source data.

Grateful for your help!

2 Answers 2

5
Insert into newtable 
    select ID,Nbr,max(Data1),max(Data2),max(Data3) from table group by Nbr

Try this and let me know it worked or not

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

1 Comment

you have to watch out for nulls
4
SELECT Nbr, 
           Max(data1) data1, 
           Max(data2) data2, 
           Max(Data3) data3 
    FROM   table 
    GROUP  BY Nbr 

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.