Questions tagged [null]

A database concept used to represent missing, unknown or inapplicable data.

NULL is a concept in SQL databases (exact implementation can vary) that is used to represent unknown, missing or inapplicable data. Normally it is considered to be a state of the data as opposed to the value of the data.

Ordinary equivalence comparisons do not work with NULL for the above reason. A field IS NULL (correct) as opposed to field = NULL (not correct).

NULL handling can be contentious as some believe NULL has no place in a database, and others use it for business logic. An important distinction is that NULL row values are not considered for most functions such as SUM(col_name), and correct results are obtained if NULL values are used; incorrect results are obtained if "magic" values are used to indicate no data. On some database products, the can perform better if NULL values are used correctly.

NULLs can also be dangerous and lead to unexpected results when used with the NOT IN operator.

A good analogy for the meaning of NULL is:

You are at a party with some people you know and some others you don't.

There are 3 men that you know and 4 men that are strangers. To you at that time, those 4 men have a name of NULL - you know they have names, but you do not know what they are.

If you were asked "Is that person Bill?" the answer would be I don't know - which is what most RDBMS will return as well when asked about a value being equal to NULL.

However, you would not be able to say "His name is not Bill or Jim", which is why NULL will not return TRUE (which in this case means "no match") when used with a NOT IN comparison.

345 questions
6
votes
7 answers

Database table and NULLs

I know that there have been many opinions/sides concerning NULL values in a database. I have not understood though what is the best practice for this. I.e. if I have a relational table with an optional attribute i.e. it can take NULL value -so we…
Cratylus
  • 1,003
  • 3
  • 12
  • 18
3
votes
0 answers

To NULL or not to NULL?

Possible Duplicate: Why shouldn't we allow NULLs? I've heard that it's a bad idea to do database design such that nullable fields exist. However, eliminating nullables often cause much more complex schemas. Given a schema where elimination of the…
Billy ONeal
  • 571
  • 2
  • 5
  • 7
1
vote
1 answer

Populate one table with data from another one on selected cells

I have a problem with filling empty cells in one table with data from another one. I got a table with user emails - some of the fields are empty, some are already containing emails. I gathered the list of emails from the users who doesn't have…
AKarpun
  • 113
  • 3
0
votes
1 answer

How does a NULL value get created in the various DBMS?

I'm wondering if the creation of a NULL value is standardized across the various DBMS and, if not, how it differs across them.
0
votes
0 answers

What is the commonly-accepted practice to denote the different meaning of NULLs?

I am thinking about what's the meaning of NULL in my database systems. In some columns it mean unknown / missing data. In some columns it mean a not-applicable field. In some columns it mean the entity represented does really not have the…
0
votes
1 answer

Empty result set when matching NULL?

If I run a statement such as SELECT * FROM stuff WHERE something=NULL I will get an empty result set. I know that the solution is to use something IS NULL. I also understand why: SQL interprets NULL as unknown, and it makes logical sense that if…
Manngo
  • 2,819
  • 8
  • 34
  • 56
0
votes
1 answer

Return 2 lines from a table if one line contains a column > 0 and the other is NULL

How to return 2 lines even if one line is null but the other > 0 item_id | location | quantity ------------------------------------- 14 | 1 | 10 14 | 2 | 21 | 1 | 21…
0
votes
1 answer

Joining columns with null marks into one row

I used a sub select to get the data I want. I'm struggling to merge it all into one row now though. This is an example of the result where its bike but there are loads on them: bike bike null null bike 6 6 bike bike …