简体   繁体   中英

MySQL - query with INNER JOIN + WHERE clause

SELECT `views`.* FROM `views` 
    INNER JOIN memberships ON memberships.second_id = views.user_id 
    WHERE (memberships.user_id = 1 OR views.user_id = 1)

I have this MySQL query - my problem is, that the second part of WHERE clause doesn't work, are fetched only rows, which equals memberships.user_id = 1 , but already not OR views.user_id = 1 .

Why not? What's wrong?

那是因为您要加入memberships.second_id也许应该是memberships.user_id=views.user_id因为如果条件memberships.user_id=1为真,则views.user_id等于memberships.second_id,并且second_id可能不等于1个

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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