0

我有一个 MySQL JOIN 查询,其中连接了 2 个表以获取输出

select distinct (a.error_type),a.links_id, a.crawl_cycle , b.* from $table a inner join crawler_error_type b on a.error_type = b.error_type where a.projects_id = '$pid' and b.error_priority_page_level='High'

现在我想检查该字段的值error_type是否存在于第三个表中。如果它存在,那么它不应该给我结果行。

4

3 回答 3

0

您需要再添加INNER JOIN一个third_table

SELECT DISTINCT a.error_type, a.links_id, a.crawl_cycle , b.* 
FROM  $table a 
      INNER JOIN crawler_error_type b 
          ON a.error_type = b.error_type 
      INNER JOIN third_table c
          ON a.error_type = c.error_type 

WHERE a.projects_id = '$pid' AND 
      b.error_priority_page_level='High'.
于 2012-07-25T07:27:42.220 回答
0

添加以下内容:

LEFT OUTER JOIN third_table c ON c.error_type = a.error_type 

WHERE c.error_type is null

LEFT OUTER JOIN 将显示连接到 third_table 的表中的所有记录。由于您不希望从 third_table 中匹配错误类型的记录,请使用WHERE c.error_type is null

于 2012-07-25T07:29:26.173 回答
0

如果我理解正确,您应该能够内连接第三个表。如果内部联接在联接表中有记录,则内部联接将显示该记录。如果我理解错了,请您详细说明。谢谢

select distinct (a.error_type),a.links_id, a.crawl_cycle , b.* 

from $table a 

inner join crawler_error_type b on a.error_type = b.error_type 

inner join some_table_3 c on c.error_type = a.error_type 

where a.projects_id = '$pid' and b.error_priority_page_level='High'
于 2012-07-25T07:31:18.357 回答