----- Original Message ----- From: "Martin Rytz" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, November 10, 2004 9:45 AM Subject: Suppress the 0 value
> Hi MySQL-Users > > I have a simple select statement like 'select id from table'. The result is > 0, becaues the id field is 0 (int-field). > > My problem is now how to suppress the 0 and give NULL instead of 0 as the > result (i.E. everytime the result from the select is 0 it should be NULL). > > How can this be done within the select-statement? > I'm curious about why you would want to do such a thing. Are you aware of the meaning of NULL? NULL is generally understood in the relational database community to mean "unknown or not applicable" and is NOT the same as 0. As an example to make the distinction clear, I would store a 0 in a student test score table if the student actually got every answer on the test wrong. I would store a NULL if the student didn't write the test because of illness. Then, when calculating the class average for the test, the students who had null scores would be ignored so that they wouldn't bring down the class average while students who really did get every question wrong would have their grades lower the class average. That makes more sense than having the class average lowered also by students who simply didn't write the test for some reason. I think the question you have to ask yourself is which you want to store in the table itself: 0 or NULL. If you want to see NULL when you display the data, maybe you should be storing NULL, not zero. While there are ways to do what you want to do, I think you need to be sure that you really want to translate a 0 to a NULL before going ahead and doing it. Rhino -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]