views:

98

answers:

2

I have this as a sql statement. What does it do

IF(`table`.`field1` IS NULL, 
   '', 
   GROUP_CONCAT(DISTINCT `table`.`field1`  ASC SEPARATOR ',')
   ) AS `MyNewFields`, 
+8  A: 

The portion of the SELECT clause you provided will return a zero length string if the TABLE.field1 value is null.

If the value is not null, it will use the GROUP_CONCAT function to return a comma delimited string based on the TABLE.field1 values for the group by clause (which we can't see). Example output:

MyNewFields
-------------
a,b,c
OMG Ponies
+1 was writing approximately the same as you, when i noticed your answer
moi_meme
+1, OMG Ponies is on top of SQL stuff
JYelton
A: 

Inside the IF statement, it's checking to see if Field1 of Table is null, and returns an empty string if it is. If not, it calls the GROUP_CONCAT extension method that returns a comma separated, ascending ordered list of the distinct values from Field1 in the Table.

beaudetious