Thursday, 5 March 2020

mysql concat two field with null

https://dba.stackexchange.com/questions/110949/how-to-exclude-null-values-inside-concat-mysql


MySQL concat  return null if one of the concated fields is null .
to avoid this issue use
CONCAT_WS(" ","field_one","field_two","and so on")

Wednesday, 4 March 2020

select if condition in mysql

https://stackoverflow.com/questions/31962449/mysql-select-column-if-not-null-only

SELECT IFNULL(firstname,'') AS firstname, 
IFNULL(lastname,'') AS lastname, 
IFNULL(age,'') AS age, 
IFNULL(gender,'') AS gender 
FROM persons WHERE id = 1;