0

I want to add value in database as 1,2,3 but when database contain null value it adds like ,1,2,3 my query as How to avoid , added when field is null.

 DB::table('table_user_create_activity')
               ->where(['activity_id'=>$query_get_activity->activity_id])
              ->update(['accepted_join_id'=>DB::raw("CONCAT_WS(',', ifnull(accepted_join_id,''),".$get_user_id.')')]);
  • Why not wrap the `ifnull` around or add some kind of `CASE`? Are you sure that `CONCAT_WS` on an empty column really outputs a single `,`? – Nico Haase Jul 11 '19 at 12:35
  • If database contain null value and i want to save new value , then it first add , and then value. Plz change query – user11708206 Jul 11 '19 at 12:37
  • 1
    Better thing would be to stop storing comma separated values. Dont do this; normalize the DB. Thanks me later :) Read: [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) – Madhur Bhaiya Jul 11 '19 at 12:37
  • @MadhurBhaiya actually each time user_id is appended with old user_id – user11708206 Jul 11 '19 at 12:41

0 Answers0