Php 不重复地联接3个表的替代方法
我在mysql中有3个表,表A、B和C。Php 不重复地联接3个表的替代方法,php,mysql,Php,Mysql,我在mysql中有3个表,表A、B和C。 C与B(B_id)有关系,B与a(a_id)有关系 这意味着A有许多B,B有许多C。要全部选择,我有以下查询: SELECT a.id, a.name, a.text, b.ptext, c.ctext FROM tableA as a JOIN tableB as b ON (b.p_id = a.id) JOIN tableC as c ON (c.p_pid = b.pid) WHERE a.id = 1 其中返回以下
C与B(B_id)有关系,B与a(a_id)有关系 这意味着A有许多B,B有许多C。要全部选择,我有以下查询:
SELECT a.id, a.name, a.text, b.ptext, c.ctext
FROM tableA as a
JOIN
tableB as b
ON
(b.p_id = a.id)
JOIN
tableC as c
ON
(c.p_pid = b.pid)
WHERE a.id = 1
其中返回以下内容:
| ID | NAME | TEXT | BTEXT | CTEXT |
|----|-------|--------------|--------|--------|
| 1 | page1 | futkdvthsa_1 | post_1 | thing1 |
| 1 | page1 | futkdvthsa_1 | post_2 | thing2 |
| 1 | page1 | futkdvthsa_1 | post_2 | thing3 |
有没有可能得到这样的东西:
id | name | text | posts
1 | page1 | futkdvthsa_1 | posts (post_1 = ( thing1 ), post_2 = ( thing2, thing3 ) )
每个表的单个查询或需要以php方式执行的查询
另外,这将是一个带有自定义表的wordpress插件。我想最简单的方法是用php实现。 您必须使用存储过程将字段与sql连接起来。问题的可能重复之处在于“C”中有一些序列化列。不会导致分离器组出现问题吗?