2012-07-25 60 views
0

我有一个MySQL连接查询,其中2个表的连接,以获得输出查身份证加入3个表

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的值是出现在第三个表。如果它存在,那么它不应该给我结果行。

回答

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的表格。由于您不希望与第三个表匹配错误类型的记录,请使用WHERE c.error_type is null

0

您需要在third_table增加一个INNER JOIN为:

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'. 
0

如果我的理解正确,那么您应该能够内联第三个表。内部连接将显示记录,如果他们在连接表中有记录。如果我误解了,请您详细说明。 Thx

​​