Yesideez Posted February 22, 2007 Share Posted February 22, 2007 I've just read the section in the MySQL manual on NULL and I understand not a word of it. It makes no sense and may as well be DIY instructions converted from Chinese to English by someone who only speaks Russian. Please can anyone supply an example (like a roll play) where NULL would be used and how it would benefit being used? I understand some silly stuff like MSB and LSB from my assembler programming days but something this simple has me completely stumped! Quote Link to comment https://forums.phpfreaks.com/topic/39704-solved-explanation-for-null-please/ Share on other sites More sharing options...
fenway Posted February 22, 2007 Share Posted February 22, 2007 Ok, it's like this: you need to use NULL whenever you need to be able to tell the difference between "no value specified" and "none/zero/nothing". For example, if you were storing the answer to the question "How many brothers do you have?", and the question was optional, how would you store these two possible scenarios? You can't simply store the number, because does zero mean the question wasn't answered or the user actually has _no_ brothers? Quote Link to comment https://forums.phpfreaks.com/topic/39704-solved-explanation-for-null-please/#findComment-191694 Share on other sites More sharing options...
Yesideez Posted February 22, 2007 Author Share Posted February 22, 2007 Mmmm, still don't understand! Quote Link to comment https://forums.phpfreaks.com/topic/39704-solved-explanation-for-null-please/#findComment-191740 Share on other sites More sharing options...
artacus Posted February 23, 2007 Share Posted February 23, 2007 Good golly! Like fenway said, NULL means "no value specified". If you were a row in his database and had a value of '0' for num_brothers, I'd know you had no brothers. If you had NULL for num_brothers, you may or may not have brothers. NULL is saying we don't know the answer to that question. Quote Link to comment https://forums.phpfreaks.com/topic/39704-solved-explanation-for-null-please/#findComment-191801 Share on other sites More sharing options...
cmgmyr Posted February 23, 2007 Share Posted February 23, 2007 NULL pretty much means "empty"...that section of data is not filled. Quote Link to comment https://forums.phpfreaks.com/topic/39704-solved-explanation-for-null-please/#findComment-191815 Share on other sites More sharing options...
btherl Posted February 23, 2007 Share Posted February 23, 2007 Have you ever filled out forms that look like this? [] Yes [] No [] Not sure The "not sure" is what null was designed for. Looking at how it's used may help to understand it. For example, if you sort products by price, you typically want products with a NULL price to be ignored or placed last, because NULL means "We don't know the price". Or maybe you want to fetch all products where you don't know the price, so you can fix them by setting the price. Then you would fetch all products "WHERE price IS NULL". If you wanted all products with a price set, you would fetch all products "WHERE price IS NOT NULL". If you wanted all products which were free, you would fetch all products "WHERE price = 0", which is different from all products which haven't had a price set yet. Quote Link to comment https://forums.phpfreaks.com/topic/39704-solved-explanation-for-null-please/#findComment-191833 Share on other sites More sharing options...
worldworld Posted February 23, 2007 Share Posted February 23, 2007 NULL means empty data in that field of the table. Quote Link to comment https://forums.phpfreaks.com/topic/39704-solved-explanation-for-null-please/#findComment-191906 Share on other sites More sharing options...
Yesideez Posted February 23, 2007 Author Share Posted February 23, 2007 Many thanks to cmgmyr and btherl - I now understand how and when to use this especially thanks to btherl for the excellent description on how it's used. I used to pick things up so quickly but I guess old age is setting in at last Quote Link to comment https://forums.phpfreaks.com/topic/39704-solved-explanation-for-null-please/#findComment-192324 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.