0
[TABLE1]

 +----------+-------------------+
 | USERNAME | POST              |
 +----------+-------------------+
 | Bob      | 'Hi There'        |
 | Jack     | 'Hello'           |
 | Bob      | 'Today is Monday' |
 +----------+-------------------+

 [TABLE2]

 +----------+-----------+
 | USERNAME | FOLLOWING |
 +----------+-----------+
 | Mike     | Jack      |
 | Jack     | Bob       |
 | Bob      | Jack      |
 | Jack     | Mike      |
 +----------+-----------+

我正在使用这个 join 语句:

 SELECT t1.* FROM TABLE1 t1 INNER JOIN table2 t2 
 ON t1.username = t2.following AND t2.username = 'jack';

这可行,但除了返回这些结果之外,我还想添加“OR t1.USERNAME = 'jack';

然后是另一个 OR .. 有没有办法进行连接,但还有一个 OR 语句

4

4 回答 4

1

将该条件放在一个where子句中

SELECT t1.* FROM TABLE1 t1
INNER JOIN table2 t2  ON t1.username = t2.following
where t2.username = 'jack'
OR t1.USERNAME = 'jack'
于 2012-07-23T10:15:36.173 回答
1

您应该在括号内指定多个 OR 条件:

SELECT t1.* 
FROM TABLE1 t1 
     INNER JOIN table2 t2  
         ON t1.username = t2.following 
            AND (t2.username = 'jack' OR t2.username = 'John' OR t2.username = 'Tom');
于 2012-07-23T10:16:38.520 回答
0

是的,你可以这样做

 SELECT t1.* FROM TABLE1 t1 INNER JOIN table2 t2 ont1.colName1=t2.Colname2 where colname ='value' or colname='vaue1' or colname='value';
于 2012-07-23T10:17:00.363 回答
0

简化方法

SELECT t1.* FROM TABLE1 t1 
INNER JOIN table2 t2  ON t1.username = t2.following 
where 'jack' in (t1.USERNAME,t2.username)
于 2012-07-23T10:26:39.077 回答