Search code examples
sqloracle-databaseselect-query

select count(1) from tablename where column=column


Question from interview:

  • We have table with name = tablename and some column.
  • We don't know column type.
  • SQL request: select count(1) from tablename where column=column

What result does this request return and why?


Solution

  • This returns the number of rows where column is not null, because NULL = NULL yields UNKNOWN which evaluates to false in the condition. For all other values column = column is true.