質問編集履歴
3
誤字を訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
VALUES
|
60
60
|
|
61
|
-
(1, '赤くて緑で紫'),(2, '緑'),(3, '
|
61
|
+
(1, '赤くて緑で紫'),(2, '緑で紫'),(3, '赤'),(4, '青'),(5, '赤くて紫')
|
62
62
|
|
63
63
|
;
|
64
64
|
|
2
欲しい結果を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,6 +14,28 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
+
###欲しい結果
|
18
|
+
|
19
|
+
「redとpurpleのタグを持つ記事」とは「tag_id=1とtag_id=5を持つ記事」になります。
|
20
|
+
|
21
|
+
つまり「post_id=1とpost_id=5の記事」であり以下の結果が欲しいです。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|ID|content|
|
26
|
+
|
27
|
+
|:--:|:--:|
|
28
|
+
|
29
|
+
|1|赤くて緑で紫|
|
30
|
+
|
31
|
+
|5|赤くて紫|
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
17
39
|
###テーブル設計
|
18
40
|
|
19
41
|
CREATE、INSERTです。
|
1
テーブル設計を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,11 +20,15 @@
|
|
20
20
|
|
21
21
|
```MySQL
|
22
22
|
|
23
|
-
CREATE TABLE wp_posts
|
23
|
+
CREATE TABLE wp_posts (
|
24
24
|
|
25
|
-
|
25
|
+
`ID` int,
|
26
26
|
|
27
|
+
`content` varchar(100),
|
28
|
+
|
29
|
+
PRIMARY KEY (`ID`)
|
30
|
+
|
27
|
-
;
|
31
|
+
);
|
28
32
|
|
29
33
|
INSERT INTO wp_posts
|
30
34
|
|
@@ -38,11 +42,17 @@
|
|
38
42
|
|
39
43
|
|
40
44
|
|
41
|
-
CREATE TABLE wp_tags
|
45
|
+
CREATE TABLE wp_tags (
|
42
46
|
|
43
|
-
|
47
|
+
`ID` int,
|
44
48
|
|
49
|
+
`tag_name` varchar(10),
|
50
|
+
|
51
|
+
PRIMARY KEY (`ID`),
|
52
|
+
|
53
|
+
INDEX index_wp_tags_1 (`tag_name`)
|
54
|
+
|
45
|
-
;
|
55
|
+
);
|
46
56
|
|
47
57
|
INSERT INTO wp_tags
|
48
58
|
|
@@ -56,21 +66,29 @@
|
|
56
66
|
|
57
67
|
|
58
68
|
|
59
|
-
CREATE TABLE wp_tag_holders
|
69
|
+
CREATE TABLE wp_tag_holders (
|
60
70
|
|
71
|
+
`tag_ID` int,
|
72
|
+
|
73
|
+
`post_ID` int,
|
74
|
+
|
75
|
+
CONSTRAINT foreign_wp_tag_holders_01 FOREIGN KEY (`tag_ID`) REFERENCES wp_tags(`ID`),
|
76
|
+
|
77
|
+
INDEX index_wp_tag_holders_1 (`post_ID`)
|
78
|
+
|
79
|
+
);
|
80
|
+
|
81
|
+
INSERT INTO wp_tag_holders
|
82
|
+
|
61
|
-
(`tag_ID`
|
83
|
+
(`tag_ID`,`post_ID`)
|
84
|
+
|
85
|
+
VALUES
|
86
|
+
|
87
|
+
(1, 1),(2, 1),(5, 1),(2, 2),(5, 2),(1, 3),(3, 4),(1, 5),(5, 5)
|
62
88
|
|
63
89
|
;
|
64
90
|
|
65
|
-
INSERT INTO wp_tag_holders
|
66
91
|
|
67
|
-
(`post_ID`,`tag_ID`)
|
68
|
-
|
69
|
-
VALUES
|
70
|
-
|
71
|
-
(1, 1),(1, 2),(1, 5),(2, 2),(3, 5),(3, 1),(4, 3),(5, 1),(5, 5)
|
72
|
-
|
73
|
-
;
|
74
92
|
|
75
93
|
```
|
76
94
|
|