I have 2 MySql tables. users with id's and username's ; streams with userId's and streamId's How to get them as / join them into one table containing only
username | streamId
as SQL response? With one SQL query.
views:
48answers:
3
+2
A:
you can do the following:
select a.username, b.streamId
from names a, streams b
where a.userId = b.userId;
noinflection
2010-05-07 19:55:28
I think you might need a JOIN or something in there, but it seems like this would work.
MiffTheFox
2010-05-07 19:57:44
Technically a comma between tables is a JOIN, its just old school syntax.
MindStalker
2010-05-07 20:02:16
+2
A:
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.
Nate Noonen
2010-05-07 19:58:33
A:
select u.username, max(s.streamId) as streamId
from users u
inner join streams s on u.id = s.userId
group by u.username
RedFilter
2010-05-07 19:58:44