MySQL - 使用INNER JOIN + WHERE子句进行查询

时间:2012-02-06 16:00:25

标签: mysql database inner-join where-clause where

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

我有这个MySQL查询 - 我的问题是,WHERE子句的第二部分不起作用,只提取行等于memberships.user_id = 1,但已经不是OR views.user_id = 1

为什么不呢?怎么了?

1 个答案:

答案 0 :(得分:1)

那是因为你加入memberships.second_id也许它应该是memberships.user_id=views.user_id,因为如果条件memberships.user_id=1为真,则views.user_id等于memberships.second_id,而second_id可能不是等于1