0
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 3 years have passed since last update.

SELECTで抽出する際にNULLだけのカラムを追加したい時(MySQL)

Posted at

何らかの事情で、NULLだけのカラムを作りたい場合、

SELECT
Code AS code,
Name AS name,
Continent,
IndepYear,
nullif('','') AS ALLNULL
FROM
country
;

このように書いてあげれば

code name Continent IndepYear ALLNULL
ABW Aruba North America NULL NULL
AFG Afghanistan Asia 1919 NULL
AGO Angola Africa 1975 NULL
AIA Anguilla North America NULL NULL

NULLだけのカラムを作り出せます。

nullif('','')の応用です。

nullifについては以前書いたのでこちらを参考にしてもらえればと思います。
MySQLでSELECTにて抽出するときに出る空文字をNULLに変換する。

0
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
0
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?