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 combine datas with same column and ignore null values in mysql

I’m just going to ask how to query combine datas with same column and ignore all null values

actual table:

 id |   first_name  |   last name  |    age   |   unique_id 
  1 |      Doe      |              |          |         111
  2 |               |     John     |          |         111
  3 |               |              |     32   |         111
  4 |      Reeves   |              |          |         222
  5 |               |      Keanu   |          |         222

wanted query result :

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

      first_name  |   last name  |    age   |   unique_id 
          Doe     |     John     |     32   |      111
          Keanu   |     Reeves   |          |      222
  

Thanks!!

>Solution :

Aggregate by unique_id and use MAX:

SELECT
    unique_id,
    MAX(first_name) AS first_name,
    MAX(last_name) AS last_name,
    MAX(age) AS age
FROM yourTable
GROUP BY
    unique_id;
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