0

Context: I was practicing some SQL questions on stratascratch.com when I came across this one:

De Morgan's laws in SQL

https://platform.stratascratch.com/coding-question?id=9648&python=

The hint says that "Drafted means pickround value (int64 type) is not NULL or 0. According to my understanding, this means pickround value must be NOT NULL OR NOT 0, which is the standard solution to the question. Hence, by De Morgan's Law, this means the equivalent expression is NOT (NULL AND 0). However, the code I wrote there reads pickround is NULL OR 0, which is the opposite of what the question specified and still my code turned out to be correct, as indicated by the green "Solved" tick mark.

My question is: am I misunderstanding the SQL syntax or am I misunderstanding the logic?

luminare
  • 363
  • 1
  • 2
  • 15
  • 1
    DISTINCT is not a function, it's a set quantifier. Remove the brackets to write clearer code, i.e. simply do `COUNT(DISTINCT name)`. – jarlh Oct 16 '20 at 14:12
  • `IN (NULL, 0)` will only return 0 rows, no NULL rows. (NULL is not considered to be equal to NULL.) – jarlh Oct 16 '20 at 14:14
  • @jarlh I understand your tip about DISTINCT. I will do that from now on. But I don't understand what you mean by "NULL is not considered to be equal to NULL" – luminare Oct 16 '20 at 14:20
  • `WHERE null IN (0, NULL)` will not return anything. – jarlh Oct 16 '20 at 14:21
  • Sorry I still don't understand. Why is `pickround IN (NULL, 0)` equivalent to `(pickround NOTNULL OR pickround <> '0')` – luminare Oct 16 '20 at 14:23
  • You prpbably want `... and (pickround is null or pickround = 0)`. – jarlh Oct 16 '20 at 14:27
  • I understood now, looking at this https://stackoverflow.com/questions/9581745/sql-is-null-and-null and this https://www.w3schools.com/sql/sql_null_values.asp – luminare Oct 16 '20 at 14:58

0 Answers0