# Is it possible to do a NULL comparison in Relational Algebra?

Please consider the following question given in a booklet:

I have read about databases from Database System Concepts - by Henry F. Korth, but never saw an instance where we could do a NULL comparison in relational algebra queries - unlike SQL queries.

(C) is given the correct option, but my question is:

Is the statement III given above, a valid Relational Algebra query?

Is the statement III given above, a valid Relational Algebra query?

Good question; and you're going to get different answers depending on which exact version of RA you're talking about.

III has a restriction (sigma) S.b<>null. So it's presumably expecting that the result from the outer join will "fill values" in S.b where there is no S row matching an R row.

But whatever null is, it's not a 'value'. (Codd described it as a "mark".) So in SQL you can't write ... WHERE S.b <> NULL. (Or rather you can, but it will never select any rows. ... op NULL returns false for any comparison op.)

In SQL you must write ... WHERE NOT ISNULL(S.b) (or some such) -- which shows that testing for null is not merely a comparison, because null is not merely a value.

You can choose different ways to try to make sense of nullable columns; but they all end up in some sort of gibberish like this. There simply is not any coherent semantics. I call it 'two-and-a-half value logic'.

So in any version of RA I would deal with, there's no nulls, no outer join, and III would not be a valid query.

There's a persistent confusion on stackxxx RA questions that SQL and RA are equivalent and that there's some mechanical translation between them. Well you can (as it seems in this case) add bogus semantics to RA so it's something like SQL. But why? It's putting lipstick on a pig.

Wikipedia says

The operators defined in this section assume the existence of a null value, $$\omega$$, which we do not define, to be used for the fill values; in practice this corresponds to the NULL in SQL.

"This section" is the one that defines outer joins, which are used in the query you're asking about. So the answer appears to be yes.