Ste*_*eve 4 mysql join inner-join left-join
我在我的mysql中有两个表我想根据两个表的组合查询提取结果.我尝试加入以及内部联接但没有成功的结构
tableA是
id   userid   topic
1     34       love
3     64       friendship
35    574      romance
32    253      games
95    633      football
54    26       cricket
648    63      music
tableB是
id    location     username
34      Australia    krkrff
64      india        dieiei
574     pakistan     frkfrf
253     japan        frfffrk
633     india        ifirf
26      Australia    riiri
63      Australia    frffjrr
请注意,在tableA中,userid和TableB id相同.both反映相同用户的数据.我想通过过滤tableB中的location列来显示tableA数据.假设我想显示tableB的主题并且用户属于澳大利亚那么它应该给出输出:爱板球音乐
你可以在表B中看到34,26和63属于澳大利亚所以输出是这样的.如果位置是印度,那么将是outpput
友谊和football.please告诉如何编写SQL查询.
以下应选择您所描述的内容:
select a.topic
from tableA a
join tableB b on b.id = a.userid
where b.location = 'Australia' -- or whichever location you filter on
这相当于:
select a.topic
from tableA a
join tableB b on b.id = a.userid and b.location = 'Australia'