質問

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