我有兩個包含一個公共字段的表。 下面是這兩個表的結構是如何用於合併兩個表以獲得單個結果的MySQL查詢
表1
+--ID--+--Title----+----others---+
| 123 | Title 1 | other values|
| 124 | Title 2 | other values|
| 125 | Title 3 | other values|
| 126 | Title 4 | other values|
+------+-----------+-------------+
表2
+--ID--+--Tag ID--+----others---+
| 123 | 11 | other values|
| 123 | 12 | other values|
| 123 | 13 | other values|
| 123 | 14 | other values|
| 124 | 15 | other values|
| 124 | 16 | other values|
| 125 | 17 | other values|
| 126 | 18 | other values|
+------+----------+-------------+
我想表明第ID 123
有4 tags
即11,12,13 & 14像以下表格
+--Article ID--+--Article Title--+--Tags--+--Tag IDs------+
| 123 | Title 1 | 4 | 11, 12, 13, 14|
| 124 | Title 2 | 2 | 15, 16 |
| 125 | Title 3 | 1 | 17 |
| 126 | Title 4 | 1 | 18 |
+--------------+-----------------+--------+---------------+
我對PHP和MySQL非常陌生,並試圖學習它。
有人請幫我瞭解我如何能得到理想的結果。
請向我們展示您的代碼並告訴我們您的錯誤。 –
GROUP_CONCAT將成爲您的朋友 –
提示:使用[GROUP_CONCAT](http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html) –