문제

I have a simple table with a foreign key and a constraint that the key must exist on the parent table. However, the foreign-key column in this child table allows NULL.

MySQL lets me insert a row with NULL in that column and will return it on a SELECT * FROM theTable.

But if I specifically query for such a row, it won't be returned:

SELECT * FROM bannedItems WHERE banningAppID = NULL

Is this expected behavior? I don't see this situation documented in the MySQL doc.

도움이 되었습니까?

해결책

May be try like this :

SELECT * FROM bannedItems WHERE banningAppID IS NULL

or

SELECT * FROM bannedItems WHERE ISNULL( banningAppID )

And if you need to add NOT , you would do like this :

SELECT * FROM bannedItems WHERE banningAppID IS NOT NULL

or

SELECT * FROM bannedItems WHERE NOT ISNULL( banningAppID )
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top