Asim Zaidi
Asim Zaidi

Reputation: 28284

what this sql does

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`, 

Upvotes: 0

Views: 126

Answers (2)

beaudetious
beaudetious

Reputation: 2416

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.

Upvotes: 0

OMG Ponies
OMG Ponies

Reputation: 332591

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

Upvotes: 8

Related Questions