Skip to content

Instantly share code, notes, and snippets.

@KatagiriSo
Created November 27, 2023 08:24
Show Gist options
  • Save KatagiriSo/a3adf898c991afcc7858c1f8ebee8303 to your computer and use it in GitHub Desktop.
Save KatagiriSo/a3adf898c991afcc7858c1f8ebee8303 to your computer and use it in GitHub Desktop.
sqlite3 inner joinとleft joinの例
--- sqlite3 inner joinとleft joinの例
-- table Hogeがあったら削除
drop table if exists Hoge;
-- table Hogeがなかったら作る
create table if not exists Hoge (
name varchar(255) not null,
age int not null
);
-- レコードの追加
insert into Hoge (name, age) values ('hoge', 20);
insert into Hoge (name, age) values ('fuga', 30);
insert into Hoge (name, age) values ('piyo', 40);
-- レコードの取得
select * from Hoge;
drop table if exists Special;
-- 特別テーブル Specialを作る
create table if not exists Special (
name varchar(255) not null,
skill varchar(255) not null
);
insert into Special (name, skill) values ("hoge", "Java");
select * from Special;
-- inner joinの例 
select
Hoge.*,
Special.skill from Hoge
inner join Special on Hoge.name = Special.name;
-- left joinの例
select
Hoge.*,
Special.skill from Hoge
left join Special on Hoge.name = Special.name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment