Search code examples
mysqldatabasenulltuplescriteria

How to query with null value in Tuple Criteria MYSQL


MYSQL query:

select * from CLASS where (CLASS_ID, CLASS_NAME) = (1, "FIRST");

Similarly i need for a tuple which contains null value like:

select * from CLASS where (CLASS_ID, CLASS_NAME) = (1, null);

But above query with null value doesn't work in mysql.

Can anyone help me with constructing query?


Solution

  • You can't check for NULL values using the comparison operator. Your only option is to use IS NULL.

    So you can use something like this:

    (CLASS_ID, CLASS_NAME) = (1, "FIRST") OR (CLASS_ID = 1 AND CLASS_NAME IS NULL)