[英]In a query of three tables. How to get an array of teams with their members in SQL
[英]I have 2 MySql tables. How to get not all data from them in 1 sql query?
我有2個MySql表。 具有id和用戶名的用戶; 使用userId和streamId的流如何將它們作為/加入到一個只包含username | streamId
表中 username | streamId
作為SQL響應? 使用一個SQL查詢。
你可以做到以下幾點:
select a.username, b.streamId
from names a, streams b
where a.userId = b.userId;
select tb1.username, tb2.streamid
from tb1
inner join tb2 on tb2.userid = tb1.userid
上面的響應返回相同的結果,只包含一個隱式連接,我的速度較慢。
select u.username, max(s.streamId) as streamId
from users u
inner join streams s on u.id = s.userId
group by u.username
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.