使用完全联接但不使用左联接时出现问题。为什么?

时间:2019-01-22 10:15:00

标签: mysql

当我在不同的数据库上使用left join时,它可以工作,但是当我使用inner join时却不能。为什么呢

SELECT tkblue_tklabel_dev_data.EmailContent.*, tkblue_tklabel_dev_archdata.EmailTracking.*
FROM tkblue_tklabel_dev_data.EmailContent
FULL JOIN tkblue_tklabel_dev_archdata.EmailTracking ON tkblue_tklabel_dev_archdata.EmailTracking.idEmailTracking = tkblue_tklabel_dev_data.EmailContent.idEmailTracking
  

未知表'tkblue_tklabel_dev_data.EmailContent'

但是使用时

SELECT tkblue_tklabel_dev_data.EmailContent.*, tkblue_tklabel_dev_archdata.EmailTracking.*
FROM tkblue_tklabel_dev_data.EmailContent
LEFT JOIN tkblue_tklabel_dev_archdata.EmailTracking ON tkblue_tklabel_dev_archdata.EmailTracking.idEmailTracking =
tkblue_tklabel_dev_data.EmailContent.idEmailTracking

我没有此错误消息,但只能得到左表的结果。或者,我希望所有结果都像完全加入一样。

1 个答案:

答案 0 :(得分:0)

完全连接在mysql中不存在,但是您可以在UNION中同时使用左连接和右连接来产生相同的结果

SELECT tkblue_tklabel_dev_data.EmailContent.*
      , tkblue_tklabel_dev_archdata.EmailTracking.*
FROM tkblue_tklabel_dev_data.EmailContent
LEFT JOIN tkblue_tklabel_dev_archdata.EmailTracking  
  ON tkblue_tklabel_dev_archdata.EmailTracking.idEmailTracking = tkblue_tklabel_dev_data.EmailContent.idEmailTracking
UNION 
SELECT tkblue_tklabel_dev_data.EmailContent.*
      , tkblue_tklabel_dev_archdata.EmailTracking.*
FROM tkblue_tklabel_dev_data.EmailContent
RIGHT JOIN tkblue_tklabel_dev_archdata.EmailTracking  
  ON tkblue_tklabel_dev_archdata.EmailTracking.idEmailTracking = tkblue_tklabel_dev_data.EmailContent.idEmailTracking