Vladislav Kysliy Vladislav Kysliy - 3 months ago 14
SQL Question

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?

Answer

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.

Comments