简体   繁体   English

多对多mySQL选择

[英]Many-to-Many mySQL selection

How can I get a select result showing all the interests of a certain user. 如何获得显示特定用户所有兴趣的选择结果。 My 3 tabels look like this: 我的3个表格如下所示:

Tabel: User 表格:用户
-- ID - ID
-- first_name - 名字
-- last_name - 姓
-- etc... -等等...

Tabel: Interests Tabel:兴趣
-- ID - ID
-- title -标题

Tabel: User_Interests 表格:User_Interests
-- User_ID - 用户身份
-- Interests_ID -Interests_ID

This is what I got so far: 这是我到目前为止所得到的:

SELECT 
    User.ID, User.first_name
FROM
    User
        INNER JOIN
    User_Interests ON User_Interests.User_ID = User.ID
WHERE
    User.ID = 0

    enter code here

You need just also join to Interests table 您还需要加入Interests

Try this: 尝试这个:

SELECT 
User.ID, User.first_name, Interests.title 
FROM  User
INNER JOIN User_Interests 
ON User_Interests.User_ID = User.ID
INNER JOIN Interests 
ON User_Interests.Interests_ID = Interests.ID 
WHERE
User.ID = 0

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

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