[英]I have 2 MySql tables. How to get not all data from them in 1 sql query?
I have 2 MySql tables. 我有2个MySql表。 users with id's and username's ;
具有id和用户名的用户; streams with userId's and streamId's How to get them as / join them into one table containing only
username | streamId
使用userId和streamId的流如何将它们作为/加入到一个只包含
username | streamId
表中 username | streamId
as SQL response? username | streamId
作为SQL响应? With one SQL query. 使用一个SQL查询。
you can do the following: 你可以做到以下几点:
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
The response above returns the same results, just contains an implicit join which my be slower. 上面的响应返回相同的结果,只包含一个隐式连接,我的速度较慢。
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.