mysql查询联接/内部联接

编程入门 行业动态 更新时间:2024-10-27 12:35:28
本文介绍了mysql查询联接/内部联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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 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是相同的.两者都反映了相同用户的数据.我想通过过滤来自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查询联接/内部联接

本文发布于:2023-10-15 00:42:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492729.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!