我有两个疑问。首先 -
SELECT
communications.creation_date as message_date,
message as message_text,
employees.first_name || ' ' || coalesce(employees.middle_name,'') || ' ' || employees.last_name as message_by
FROM app.communications
INNER JOIN app.employees ON communications.message_from = employees.emp_id
WHERE send_as_sms = TRUE AND com_id = (SELECT MAX(com_id) FROM app.communications)
基本上输出 -| message_date | message_text | message_by |
第二个查询 -
SELECT
cs.com_id,
cs.first_name ||' ' || cs.last_name AS recipient_name,
cs.sim_number AS phone_number
FROM app.communication_sms cs
WHERE cs.com_id = (SELECT MAX(cs2.com_id) FROM app.communication_sms cs2)
ORDER BY first_name ASC
输出 -| com_id | recipient_name | phone_number |
从查询中可以看出,两个表都有一"com_id"
列。我需要做一个单一的查询,将上面的两个查询合并以获得一个输出,比如 -
|message_date|message_text|message_by|recipient_name|phone_number|
我怎样才能做到这一点?UNION
由于不同的数据类型和不同的列数,我无法使用。我会感谢你们的帮助。