回答編集履歴
1
sample
test
CHANGED
@@ -1 +1,43 @@
|
|
1
1
|
product_idに対してmail_typeの1,3が固定なら正規化するのが普通です
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
# sample
|
6
|
+
|
7
|
+
```SQL
|
8
|
+
|
9
|
+
create table products(product_id int unique,name varchar(10));
|
10
|
+
|
11
|
+
insert into products values
|
12
|
+
|
13
|
+
(1,'test1'),(2,'test2'),(4,'test4');
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
create table mail_products(product_id int unique);
|
18
|
+
|
19
|
+
insert into mail_products values(1),(3),(5);
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
create table types(mail_type int unique);
|
24
|
+
|
25
|
+
insert into types values(1),(3);
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
select * from mail_products,types;
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
ここでmail_productsに対してproductsのデータを流し込んで再表示
|
34
|
+
|
35
|
+
```SQL
|
36
|
+
|
37
|
+
insert ignore into mail_products select product_id from products;
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
select * from mail_products,types;
|
42
|
+
|
43
|
+
```
|