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 1 year has passed since last update.

【PostgreSQL】<>演算子を使うと、nullのレコードも除外される

Posted at

テーブルAには、8028件のレコードがあります。

select
    count(*) 
from
    public.tablea ;

実行結果
8028

このうち、remarksカラムがnullのレコードが4354件あります。

select
    count(*) 
from
    public.tablea
WHERE
    ( 
        remarks is null
    );
実行結果
4354

さて、remarksが「aaa」でないレコードを取得したいとします。

select
    remarks
from
    public.tablea
WHERE
    ( 
        remarks <> 'aaa'
    );

取得結果:
remarksがnullのレコードも除外され、取得されませんでした。

image.png


nullのレコードも取得したい場合は、orでつなぐ必要があります。

select
    remarks
from
    public.tablea 
WHERE
    ( 
        remarks <> 'aaa'
        or remarks is null
    );
1
0
1

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?