2
做N + 1個查詢來查詢我有2個表如何在沒有在MySQL
users_table
id | first_name
1 | first name1
2 | first name2
addresses_table
id | user_id | address
1 | 1 | first address of user 1
2 | 1 | second address of user 1
3 | 2 | first address of user 2
4 | 2 | second address of user 2
欲像這樣的表結果,第一列是users_table如first_name和第二列中的每個用戶的分離的愛好用逗號
<table>
<tr>
<td>first name1</td><td>first address of user 1, second address of user 1</td>
</tr>
<tr>
<td>first name2</td><td>first address of user 2, second address of user 2</td>
</tr>
</table>
,如果我要查詢它必須select * from users_table
然後讓每個用戶喜歡select * from addresses_table where user_id = 1
這是不是很有效,這可以用奧姆斯防止的地址,但我想知道我們可以防止N + 1查詢使用SQL
您是否試圖使用html來表示所需的輸出?或不同你想在html – Strawberry
哪個愛好輸出??? –
查找'group_concat' –