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

I have 2 MySql tables. users with an identifier and username; streams with userId and streamId. How to get them as / append them to a single table containing only username | streamIdas an SQL response? With one SQL query.

+3
source share
3 answers

you can do the following:

select a.username, b.streamId
from names a, streams b
where a.userId = b.userId;
+2
source
select tb1.username, tb2.streamid 
from tb1
inner join tb2 on tb2.userid = tb1.userid

The answer above returns the same results, just contains an implicit connection, which is slower for me.

+2
source
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
source

Source: https://habr.com/ru/post/1744556/


All Articles