MySQL连接表返回空结果

时间:2018-11-16 16:59:25

标签: mysql

我正在尝试从多个表中获取数据。

当我尝试从单个表中获取数据时,效果很好

SELECT p.ID, 
       p.post_title, 
       p.post_status,
       a1.default_category, 
       a1.post_category,
       a1.latitude, 
       a1.longitude
FROM   wp_posts AS p, 
       wp_geodir_gd_education_detail AS a1
WHERE  p.post_status = 'publish' 
       AND p.ID = a1.post_id
       AND ( Find_in_set(31, a1.post_category) 
              OR Find_in_set(32, a1.post_category) 
              OR Find_in_set(249, a1.post_category) 
              OR Find_in_set(246, a1.post_category) 
              OR Find_in_set(33, a1.post_category) 
              OR Find_in_set(34, a1.post_category) 
              OR Find_in_set(35, a1.post_category) 
              OR Find_in_set(245, a1.post_category) ) 

但是当我尝试将其与多个表一起使用时,它会失败

   SELECT p.ID, 
       p.post_title, 
       p.post_status,
       a1.default_category, 
       a1.post_category,
       a1.latitude, 
       a1.longitude, 
       a2.default_category, 
       a2.latitude, 
       a2.longitude,
       a2.post_category
FROM   wplh_posts AS p, 
       wplh_geodir_gd_education_detail AS a1, 
       wplh_geodir_gd_accommodation_detail AS a2 
WHERE  p.post_status = 'publish' 
       AND p.ID = a1.post_id 
       AND p.ID = a2.post_id 
       AND ( Find_in_set(31, a2.post_category) 
              OR Find_in_set(32, a2.post_category) 
              OR Find_in_set(249, a2.post_category) 
              OR Find_in_set(246, a2.post_category) 
              OR Find_in_set(33, a2.post_category) 
              OR Find_in_set(34, a2.post_category) 
              OR Find_in_set(35, a2.post_category) 
              OR Find_in_set(245, a2.post_category) 
              OR Find_in_set(175, a1.post_category) 
              OR Find_in_set(39, a1.post_category) 
              OR Find_in_set(223, a1.post_category) 
              OR Find_in_set(209, a1.post_category) 
              OR Find_in_set(181, a1.post_category) 
              OR Find_in_set(185, a1.post_category) ) 

在第二个查询中返回空结果。我尝试使用OR进行第二次查询,但没有帮助。

0 个答案:

没有答案