我想获取表数据,而子数据位于另一个表中,但是我不知道如何进行查询。
我知道该怎么做是普通的查询选择*表格1,我知道如何执行“内部联接”,但我不想重复表1“父”中的数据
select * form parent INNER JOIN childs on parent.pnt_id=childs.id_pnt;
父母子女
+-----+----------+------+-------+ +-----+----------+-------+
| id | pnt_id | info |infotwo| | id | id_pnt |n_child|...
+-----+----------+------+-------+ +-----+----------+-------+
| 1| 5| home | big | | 5| 1| joan |
+-----+----------+------+-------+ +-----+----------+-------+
| 2| 3| work | fat | | 3| 1| luci |
+-----+----------+------+-------+ +-----+----------+-------+
| 3| 0| soft | thin | | 6| 2| troy |
+-----+----------+------+-------+ +-----+----------+-------+
我想要
形式的查询$parents = arrar (
info -> "home",
infotwo -> "big",
data_child -> arrar (
n_child -> "joan",
n_child -> "luci"
)
)
答案 0 :(得分:0)
我认为您想要汇总:
select p.info, p.infotwo, group_concat(n_child) as children
from parent p join
childs c
on p.pnt_id = c.id_pnt
where p.pnt_id = 1
group by p.info, p.infotwo;