2
0

More than 1 year has passed since last update.

テーブルを自己結合して九九をやらせる

Posted at

はじめに

特に実用的な内容ではありません。ネタです。
テーブルの自己結合を使って遊んでみました。

テーブル

1~9が入ったtestという名前のテーブルを用意。

select * from test;

スクリーンショット 2023-01-25 11.29.44.png

九九

九九をやらせてみます。

select test1.id, test2.id, test1.id*test2.id 
from test as test1
join test as test2;

スクリーンショット 2023-01-25 11.30.08.png

スクリーンショット 2023-01-25 11.30.25.png

ポイント

  • 同一のテーブル同士を結合させることが可能です。
  • 同名のためas句にて別名をつける必要があります。

まとめ

自己結合できるってことだけを覚えておき、必要なタイミングで活用できればいいかなと思います。

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