我有 2 个通过连接表连接的表。它们如下所示
servers serverInstances instances
| id | ip | | id | sID | iID | | id | name |
|____|____________| |____|_____|_____| |____|______|
| 11 | 10.0.0.100 | | 1 | 11 | 40 | | 40 | real |
| 12 | 10.0.0.200 | | 2 | 11 | 41 | | 41 | fake |
| 3 | 12 | 45 | | 45 | test |
通过以下查询,我可以获得以下数据
SELECT s.ip, i.name
FROM servers AS s
JOIN serverInstances AS si ON s.ID = si.sID
JOIN Instances AS i ON si.iID = i.ID
| ip | name |
|____________|______|
| 10.0.0.100 | real |
| 10.0.0.100 | fake |
| 10.0.0.200 | test |
我遇到的问题是获取上述信息,并编写一个返回以下内容的查询。
| ip | instances |
|____________|____________|
| 10.0.0.100 | real, fake |
| 10.0.0.200 | test |
是否有一种简单而动态的方法来编写此查询?