質問編集履歴
1
多対多の関係、詳細
test
CHANGED
File without changes
|
test
CHANGED
@@ -115,3 +115,39 @@
|
|
115
115
|
|
116
116
|
|
117
117
|
MySQL
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
---
|
122
|
+
|
123
|
+
[追記]
|
124
|
+
|
125
|
+
多対多の結合に関して、次のようなJOIN句を入れています。
|
126
|
+
|
127
|
+
```sql
|
128
|
+
|
129
|
+
SELECT t1.id AS id, t1.name AS name, tags.name AS tag
|
130
|
+
|
131
|
+
FROM t1
|
132
|
+
|
133
|
+
LEFT JOIN tag_relation ON t1.id = tag_relation.t1_id
|
134
|
+
|
135
|
+
LEFT JOIN tags ON tag_relation.tag_id = tags.id
|
136
|
+
|
137
|
+
ORDER BY t1.id ASC
|
138
|
+
|
139
|
+
LIMIT 3
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
テーブルとカラム
|
144
|
+
|
145
|
+
|t1|tag_relation|tags|
|
146
|
+
|
147
|
+
|:--|:--:|--:|
|
148
|
+
|
149
|
+
|id|id|id|
|
150
|
+
|
151
|
+
|name|t1_id|name|
|
152
|
+
|
153
|
+
||tag_id||
|