开发者

I have 2 MySql tables. How to get not all data from them in 1 sql query?

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜