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

Multiple concat with like not showing the output in sql

I am using multiple concat with like but I am not getting all the output from the table. I am using below SQL query below in the database.

  select 
  company_id as ID, 
  concat(
    c.list_rank, '|||', c.company_name, 
    '|||', c.company_size, '|||', c.industry
  ) as post_content, 
  c.admin_approved from company22 c where company_name like ' % XYZ % ';

I am getting below output. Post content is showing null but I have all the data in the table

enter image description here

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 :

At least one of the values you’re concatenating must be NULL. Since any operation involving NULL returns NULL, that makes the final result NULL.

Use IFNULL() to replace the null values with an empty string.

CONCAT_WS('|||', IFNULL(c.list_rank, ''), IFNULL(c.company_name, ''), IFNULL(c.company_size, ''), IFNULL(c.industry, '')) AS post_content

I also use CONCAT_WS() to simplify joining several values with the same delimiter.

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