teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

sample

2021/11/09 06:18

投稿

yambejp
yambejp

スコア117871

answer CHANGED
@@ -1,1 +1,22 @@
1
- product_idに対してmail_typeの1,3が固定なら正規化するのが普通です
1
+ product_idに対してmail_typeの1,3が固定なら正規化するのが普通です
2
+
3
+ # sample
4
+ ```SQL
5
+ create table products(product_id int unique,name varchar(10));
6
+ insert into products values
7
+ (1,'test1'),(2,'test2'),(4,'test4');
8
+
9
+ create table mail_products(product_id int unique);
10
+ insert into mail_products values(1),(3),(5);
11
+
12
+ create table types(mail_type int unique);
13
+ insert into types values(1),(3);
14
+
15
+ select * from mail_products,types;
16
+ ```
17
+ ここでmail_productsに対してproductsのデータを流し込んで再表示
18
+ ```SQL
19
+ insert ignore into mail_products select product_id from products;
20
+
21
+ select * from mail_products,types;
22
+ ```