1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【MySQL】NULL安全等価演算子でNULLを含めた一致を取る

Last updated at Posted at 2019-09-09

MySQLwhereでは検索対象がnullの場合無視されてしまうため、以下のようなクエリでは、「DBに入っているfuga_valueの値がnullかつ:paramへの入力がnull」という場合の取得ができません。

select * from hoge where fuga_value = :param;

対処法

NULL安全等価演算子を使って以下のように書けます。

select * from hoge where param <=> :param;

参考

MySQL :: MySQL 5.6 リファレンスマニュアル :: 12.3.2 比較関数と演算子

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?