title: mysql concatenate columns if column is not null
body: <p>Here is the table schema;</p>
  
  <pre><code>create table campaign (
      id INT NOT NULL,
      custom_param1 VARCHAR(15),
      custom_value1 VARCHAR(15),
      custom_param2 VARCHAR(15),
      custom_value2 VARCHAR(15),
      custom_param3 VARCHAR(15),
      custom_value3 VARCHAR(15),
      PRIMARY KEY (id)
  )
  </code></pre>
  
  <p>and this is the mock data I have;</p>
  
  <pre><code>id  custom_param1   custom_value1   custom_param2   custom_value2   custom_param3   custom_value3
  --  -------------   -------------   -------------   -------------   -------------   -------------
  1   param1          value1          param2          value2          param3          value3
  2   param1          value1          param2          value2          param3          value3
  3   param1          value1          param2          value2          param3          value3
  4   param1          value1          param2          value2          NULL            NULL
  5   param1          value1          NULL            NULL            NULL            NULL
  </code></pre>
  
  <p>Now I am trying to concatenate params and values columns like a format</p>
  
  <pre><code>param1=value1; param2=value2, param3=value3
  </code></pre>
  
  <p>if a row has only two params and values it should be like;</p>
  
  <pre><code>param1=value1; param2=value2
  </code></pre>
  
  <p>well I create a query which I can concatenate row but if one of the is null then whole row is become a null - As I know if <code>concat</code> function tries to concat a NULL value string will completely become null. And this is query I use.</p>
  
  <pre><code>select CONCAT(c.custom_param1, '=', c.custom_value1, '; ',
                  c.custom_param2, '=', c.custom_value2, '; ',
                  c.custom_param3, '=', c.custom_value3) as 'Custom Parameters'
  from campaign as c;
  </code></pre>
  
  <p>I will appreciate for any kind of help. Thanks anyway</p>