简体   繁体   English

Mysql Query来获取用户以及所有以下用户?

[英]Mysql Query to fetch users who and all following the intrest?

I'm building a app where a users can follow 'n' number of intrests.here I need to fetch the users who and all following a each intrest.for your information i have three tables as bellow 我正在构建一个应用程序,其中用户可以关注n次的intrests。在这里,我需要获取遵循每个intrests的所有用户。对于您的信息,我有以下三个表格

1)tbl_intrestmaster(master table for intrests) 1)tbl_intrestmaster(主表)

2)tbl_users(master table) 2)tbl_users(主表)

3)tbl_userintrests(fk to tbl_intrestmaster and tbl_user) 3)tbl_userintrests(从fk到tbl_intrestmaster和tbl_user)

I can do it but without processing in programming language i want to achieve this ie by using mysql query only. 我可以做到,但不使用编程语言进行处理,我想通过仅使用mysql查询来实现这一点。

So, tbl_userintrests (interest?) is a join table between users and interests? 那么,tbl_userintrests(兴趣?)是用户和兴趣之间的联接表吗? And, you're trying to get users who follow each interest? 并且,您正在尝试吸引关注每个兴趣的用户? Ok, something like this: 好的,像这样:

SELECT u.name, i.name
FROM tbl_userintrests ui
JOIN tbl_users u
ON u.id = ui.user_id
JOIN tbl_intrestmaster i
ON i.id = ui.interst_id

So you're basically saying: 所以您基本上是在说:

Give me everything in the join table Match users onto it Match interests onto it Now you should be left with users matching interests 在联接表中给我所有内容将用户匹配到上面将兴趣匹配到上面现在应该让您拥有匹配兴趣的用户

For the record, this is a very simple join table question and you may find some value in searching SO / Google for other join table examples. 记录下来,这是一个非常简单的联接表问题,您可能会在搜索SO / Google中寻找其他联接表示例时找到一些价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM