嗨,我有两个表,并且对于两个表中的同一联系人“电子邮件”,我想知道“电子邮件”的第一次联系。
联系人
到目前为止,我只做过外部联接来联接两个表,但是它删除了重复的“电子邮件”,我需要它来比较同一“电子邮件”的时差。
ALTER TABLE conversation_and_id CHANGE `email` `conversation_and_id_email` VARCHAR(100);
create table conversation_and_id_and_contact
SELECT *
FROM contact AS con
LEFT JOIN conversation_and_id AS ci ON con.email = ci.conversation_and_id_email
UNION
SELECT *
FROM contact AS con
RIGHT JOIN conversation_and_id AS ci ON con.email = ci.conversation_and_id_email;
create table final
select
if (f.email is not null, f.email, f.conversation_and_id_email) as email1,
if (f.atlas_interest is not null, f.atlas_interest, f.created_at) as time1,
if (f.conversation_and_id_email is not null, f.conversation_and_id_email, f.email) as email2,
if (f.created_at is not null, f.created_at, f.atlas_interest) as time2
from conversation_and_id_and_contact f;
答案 0 :(得分:0)
任何地方的标准解决方案是对两个表执行完全外部联接并获得eyLvv73vv73vv73vv71cdTAwMDBcdTAwMTBKRklGXHUwMDAwXHUwMDAx
XHUwMDAxXHUwMDAxXHUwMDAwSFx1MDAwMEhcdTAwMDBcdTAwMDDvv73v
v71cdTAwMDBcZkFwcGxlTWFya1xu77+977+9XHUwMDAw77+9XHUwMDAw
XHUwMDA3XHUwMDA1XHUwMDA1XHUwMDA2XHUwMDA1XHUwMDA1XHUwMDA3
XHUwMDA2XHUwMDA2XHUwMDA2XGJcdTAwMDdcdTAwMDdcYlxuXHUwMDEx
XHUwMDBiXG5cdFx0XG5cdTAwMTRcdTAwMGZcdTAwMGZcZlx1MDAxMVx1
MDAxOFx1MDAxNVx1MDAxOVx1MDAxOVx1MDAxN1x1MDAxNVx1MDAx ...
时间戳。
但是,由于MySQL还不支持完全外部联接,因此您需要对左右联接进行联合以获得所需的结果。最终的[不必要的长]查询如下:
MIN()