Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to rework data in the same SQL table and to erase null values?

I have the SQL following structure

Code label1 label2 label3
code1 sth null null
code1 null sth2 null
code1 sth null sth3
code2 null word1 null
code2 word2 null null
code2 null null word3

It is possible to change it using only SQL functions and queries into :

Code label1 label2 label3
code1 sth sth2 sth3
code2 word2 word1 word3

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Aggregate functions like min and max ignore nulls, so you could group by the code column and aggregate over the rest of them:

SELECT   code, MAX(label1), MAX(label2), MAX(label3)
FROM     mytable
GROUP BY code
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading