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.

3
  • 1
    If its just the conversion you want, UPDATE table SET title='' WHERE title IS NULL Commented Aug 28, 2021 at 7: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? Commented Aug 28, 2021 at 7:29
  • Does this answer your question? MySql Query Replace NULL with Empty String in Select Commented Jun 24, 2022 at 9:20

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

you should show a little more in an answer, like how it matches to the question.
0

You can find a detailed answer on the following link.

Hope it resolves your issue.

Thanks

1 Comment

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: meta.stackoverflow.com/tags/link-only-answers/….

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.