我在mysql中有两个表,我想根据两个表的组合查询提取结果.我尝试了连接以及内部连接,但
i have two tables in my mysql i want to extract the results based on combined query for both tables. i tried join as well as inner join but no success the structure of
tableA是
id userid topic 1 34 love 3 64 friendship 35 574 romance 32 253 games 95 633 football 54 26 cricket 648 63 musictableB是
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是相同的.两者都反映了相同用户的数据.我想通过过滤来自tableB的位置列来显示tableA数据.假设我想显示tableB的主题,并且用户属于澳大利亚,那么它应该给出输出:love 蟋蟀 音乐
Please note that in tableA userid and in TableB id is same .both reflect the data of same users.i want to display tableA data by filtering location column from tableB. suppose that i want to display topic of tableB and the users belongs to Australia then it should give output :love cricket music
您可以在表B中看到34,26& 63属于澳大利亚,所以输出是这样.如果位置是印度,则输出将是
you can see in tableB that 34,26 & 63 belongs to Australia so the output is like that. if the location is india then outpput will be
友谊和足球.请说明如何编写sql查询.
friendship and football.please tell how to write sql query.
推荐答案以下内容应选择您要描述的内容:
The following should select what you're describing:
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'更多推荐
mysql查询联接/内部联接
发布评论