3

I have this table

user_id title
1 ABCD
1 null
2 EFGH

I'am trying to get all the titles of every user id and convert null to an empty string.

I tried using this

SELECT IFNULL(title, '') FROM table WHERE user_id = 1

But it says that multiple rows returned, when I try 2 it returns a result.

Is there a way to convert all null relut to empty string if ther more than 1 result? Thanks.

Tony Stark
  • 272
  • 1
  • 10
  • 1
    If its just the conversion you want, `UPDATE table SET title='' WHERE title IS NULL` – danblack Aug 28 '21 at 07:26
  • What result would you expect for user_id 1 if there would be no null value in your input table? Just one of the input rows? A concatenation of all titles? Is it not possible in your domain to have more than one non-null title per user? – divisionby0 Aug 28 '21 at 07:29
  • Does this answer your question? [MySql Query Replace NULL with Empty String in Select](https://stackoverflow.com/questions/9560723/mysql-query-replace-null-with-empty-string-in-select) – Elias Jun 24 '22 at 09:20

2 Answers2

1

You can use COALESCE() to replace NULL with an empty string.

Sneha Ashtekar
  • 116
  • 1
  • 1
  • 6
0

You can find a detailed answer on the following link.

Hope it resolves your issue.

Thanks

  • 1
    Try to provide at least a summary of the solution so this is not a `link-only-answer`. You can read more about it here: https://meta.stackoverflow.com/tags/link-only-answers/info#:~:text=Link%2Donly%20answers%20are%20answers,information%20available%20on%20another%20page. – Erwol Feb 12 '22 at 19:26