Jump to content

not show null values in results


cougar23

Recommended Posts

Example

[pre]

mysql> SELECT * FROM testtable;

+-------------+--------+-----------+-----------+

| idtesttable | school | readscore | mathscore |

+-------------+--------+-----------+-----------+

|          1 | A      |        60 |        50 |

|          2 | A      |        40 |      NULL |

|          3 | A      |      NULL |        70 |

|          4 | B      |        40 |      NULL |

|          5 | B      |      NULL |        50 |

+-------------+--------+-----------+-----------+[/pre]

 

But you can change the NULLs by

[pre]

mysql> SELECT school,

    -> IFNULL(readscore,'') AS readscore,

    -> IFNULL(mathscore,'') as mathscore

    -> FROM testtable;

+--------+-----------+-----------+

| school | readscore | mathscore |

+--------+-----------+-----------+

| A      | 60        | 50        |

| A      | 40        |          |

| A      |          | 70        |

| B      | 40        |          |

| B      |          | 50        |

+--------+-----------+-----------+

Link to comment
Share on other sites

Perhaps I didn't word my question well.  I'm not referring to how to make a query that ignores NULLs, but a configuration setting that when MySQL outputs the results of a query it outputs a blank space instead of NULL where a value is null.  I'll provide an example.  I've seen someone who had their MySQL set up this way, same version I'm using, but that person no longer works with me.

 

Currently

+-------------+--------+-----------+------------+

| idtesttable  | school  | readscore  | mathscore  |

+-------------+--------+-----------+------------+

|          1      | A        |        60    |        50    |

|          2      | A        |        40    |      NULL    |

|          3      | A        |      NULL    |        70    |

|          4      | B        |        40    |      NULL    |

|          5      | B        |      NULL    |        50    |

+-------------+--------+-----------+-----------+

 

Desired

Currently

+-------------+--------+-----------+------------+

| idtesttable  | school  | readscore  | mathscore  |

+-------------+--------+-----------+------------+

|          1      | A        |        60    |        50    |

|          2      | A        |        40    |                |

|          3      | A        |                |        70    |

|          4      | B        |        40    |                |

|          5      | B        |                |        50    |

+-------------+--------+-----------+-----------+

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.