MySQL – group rows with different columns discarding Null values

I am fairly new and need help with this!

How can I do a SELECT in MySQL to obtain from the following Table a result that joins all the rows in one with its columns?

Table:

ID Name Type1 Type2 Type3 Type4
1 ABC 123 Null Null Null
1 ABC Null 456 Null Null
1 ABC Null Null 789 Null
1 ABC Null Null Null 900

Output:

ID Name Type1 Type2 Type3 Type4
1 ABC 123 456 789 900

I was researching and I don’t even know how to search for the function!
Thank you very much

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

exact question was asked here

SELECT ID,
       NAME,
       MAX(Type1) AS Type1,
       MAX(Type2) AS Type2,
       MAX(Type3) AS Type3
FROM tableName
GROUP BY ID,
         NAME;


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x