Returning NULL

1

I'm using this query:

SELECT GROUP_CONCAT(coluna1) as valores FROM arquivos WHERE coluna2 IN (21, 22)

It returns the values in column1 of rows whose column2 has one of the values specified.

The problem is that in this case, the value 21 is not found in the table. So I need to return a NULL. But the query is only returning the found value.

    
asked by anonymous 22.07.2014 / 16:23

1 answer

1

I do not know if this is what you need, but do a test:

select group_concat(ifnull(coluna1, 'x')) as valores
  from (select 21 coluna2 
        union
        select 22
       ) tab_aux
  left join arquivos
    on arquivos.coluna2 = tab_aux.coluna2

Note: The 'x' represents your 'null'.

    
22.07.2014 / 18:27