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?

MySQLで「ハローワールド」

MySQLで文字列を表示する方法はいくつかあります。直接的な方法はないため、この記事ではいくつかの方法を紹介します。
ぜひ試してみてください。MySQLで文字列操作を行う他の方法をご存知でしたら、ぜひ教えてください。

Standard way

image.png

Using alias

SELECT 'Hello World' AS message;

image.png

Printing using UNION

SELECT 'Hello World'
FROM (
    SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
) t;

image.png

how does this work?

SELECT 1
UNION ALL SELECT 2
UNION ALL SELECT 3
UNION ALL SELECT 4
UNION ALL SELECT 5

これにより、以下のような一時テーブルが作成されます。
col1
1
2
3
4
5

さて、今度は select 'hello world' これは定数を設定するもので、from t は UNION を使って作成されたテーブルのエイリアスのようなものです。
つまり、これは厳密にはループを作成するのではなく、各行ごとに結果を繰り返すだけです。
これはパターンを作成する興味深い方法だと思ったので、ここに掲載しました!

これらは、MySQLで文字列を表示するためのいくつかの方法です!
気に入っていただけたら幸いです!

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?