Я пытаюсь создать представление из двух таблиц, объединяя их в два столбца: t1.recipient_email = t2.username
или t1.created_by = t2.id
.Как показано в псевдокоде ниже, я хочу, чтобы первое имя t2.name было получателем, а второе имя t2.name было именем отправителя.Я не могу придумать правильный путь для достижения этого.
CREATE VIEW emailsent_log_view
(id_email_que_log, date_sent, recipent_email, recipient_name, send_status, sender_name)
AS
SELECT
t1.id,
t1.date_send,
t1.recipient_email,
t2.name, --recipient_name: corresponds with t1.recipient_email = t2.username
t1.send_status,
t2.name --sender_name: correspond with t1.created_by = t2.id
FROM email_que_log AS t1
LEFT JOIN user_account as t2
ON t1.recipient_email = t2.username
OR t1.created_by = t2.id