cougar23 Posted May 16, 2008 Share Posted May 16, 2008 Is there a way to make MySQL not show null values when displaying the results of a query from the command line? Like for values that are NULL instead of writing NULL jus hav it be blank? Quote Link to comment Share on other sites More sharing options...
soycharliente Posted May 16, 2008 Share Posted May 16, 2008 Do you mean something like... SELECT * FROM `table` WHERE `field` != NULL Quote Link to comment Share on other sites More sharing options...
Barand Posted May 17, 2008 Share Posted May 17, 2008 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 | +--------+-----------+-----------+ Quote Link to comment Share on other sites More sharing options...
cougar23 Posted May 18, 2008 Author Share Posted May 18, 2008 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 | +-------------+--------+-----------+-----------+ Quote Link to comment Share on other sites More sharing options...
fenway Posted May 18, 2008 Share Posted May 18, 2008 I've never heard of such an option. Quote Link to comment Share on other sites More sharing options...
soycharliente Posted May 19, 2008 Share Posted May 19, 2008 I just check for NULL and output nothing using whatever language I'm programming in. PHP: <?php $var = $row['value']; echo (empty($var)) ? " " : $var; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.