GROUP_CONCAT pulling out empty result with delimiters

SELECT p.id, GROUP_CONCAT(s.size1) size1, 
GROUP_CONCAT(if (s.size2 ='', null, s.size2)) as size2, p.prod 
FROM products p JOIN stock s ON s.prodid = p.id

You can also use the NULLIF() function to convert empty strings to NULLs:

SELECT
  p.id,
  GROUP_CONCAT(       s.size1     ) AS size1,
  GROUP_CONCAT(NULLIF(s.size2, '')) AS size2,
  p.prod
FROM products AS p
  INNER JOIN stock AS s ON s.prodid = p.id
GROUP BY
  p.id,
  p.prod
;

try this:

SELECT 
    p.id, 
   GROUP_CONCAT(s.size1) size1, 
   GROUP_CONCAT(case when s.size2='' then null else s.size2 end) size2, p.prod 
FROM products p JOIN stock s ON s.prodid = p.id

Tags:

Sql

Php