Apply GROUP_CONCAT and CONCAT on a integer type value


As we know GROUP_CONCAT returns a string result with the concatenated non-NULL values from a group and CONCAT Returns the string that results from concatenating the arguments.

If we apply these function on any not char type field then it will be return result something like [BLOG-3B] and something like this. So to apply on non chars field like int type we can use CONVERT mysql function for it.

For example

SELECT concat(CONVERT(column1,char(8))," , ") AS id,group_concat(CONVERT(column2, CHAR(20)) separator '|') AS result FROM `tablename` WHERE 1 group by column1

Here CONVERT will convert value of field column1 into a char type. and CONVERT function will be work on it.



Sql Query for getting total number of empty fields in a row…

We can get total number of empty fields in a row in a table…

select SUM((`field1` = '') + (`field2` IS NULL) + ( `field3` = 0) + ...... (`fieldnth` = '')) from tablename where conditions;

Here we use
= ‘ ‘ for fields having field type string like varchar ,chars,text etc..
IS NULL is for field having default value NULL
= 0 is for field define integer type