Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL Concat not working

UPDATE profile SET favourties=CONCAT(favourties,"123") WHERE id=1

i want to append 123 in favourties but if default value of favourties is set to NULL then this query will not work. What will be query if favourties is set to NULL and then append 123 with it

like image 481
Wasim A. Avatar asked Dec 01 '22 03:12

Wasim A.


2 Answers

UPDATE profile SET favourties=CONCAT(IFNULL(favourties, ''),"123") WHERE id=1
like image 118
zerkms Avatar answered Dec 10 '22 12:12

zerkms


Wrap the field around with the COALESCE function:

UPDATE profile
SET favourties = CONCAT(COALESCE(favourties, ''),"123")
WHERE id=1
like image 43
The Scrum Meister Avatar answered Dec 10 '22 13:12

The Scrum Meister