I have 2 MySql tables. users with id's and username's ; streams with userId's and streamId's How to get them as开发者_StackOverflow / join them into one table containing only
username | streamId
as SQL response? With one SQL query.
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
精彩评论