我有一个带有ff结构的表(1):
this_table's_id | title | fk_1 | fk_2 | ...
另一个具有此结构的表 (2):
id | fk_to_this_table's_id | ...
第二个表包含指向表 1 中特定条目的多个记录。 IM 正在学习 MySQL,所以我问是否可以输出表 1 的结果,同时输出表 2 中与表 1 相关的所有内容?
这种嵌套的东西是骚乱。 我的任务是通过 PHP 输出结果,到目前为止对我来说没有问题。 我只想通过SQL查询进行指导。
编辑:输出现在很好。现在这个:如何在 PHP 中格式化它?从:
1 | item 1 | foo
2 | item 2 | bar
3 | item 3 | bar
自
<table border=1px>
<tr><td>1</td><td>item 1</td><td>foo</td></tr>
<tr><td>2</td><td>item 2</td><td rowspan=2>bar</td></tr>
<tr><td>3</td><td>item 3</td></tr>
</table>
我现在不知道该怎么做...
适应你的表名..这应该是从两个表中获取所有内容的SQL代码
select table_1.*, table_2.*
from table_1
left join table_2 on table_1_id = fk_to_table_1_id;