我有两种类型的消息,一种是私人消息,另一种是信用消息正在插入两个不同的表中。现在我正在尝试获取数据。
SELECT * ,(SELECT COUNT(*)
FROM votes
WHERE message_id = m.message_id
AND vote_type = 'like') AS likes,
(SELECT COUNT(*)
FROM votes
WHERE message_id = m.message_id
AND vote_type = 'dislike') AS dislikes
FROM messages m
WHERE 1 #and hidden is null
and recipient_id = 1
ORDER BY datetime DESC
和
SELECT * ,(SELECT COUNT(*)
FROM votes
WHERE message_id = m.message_id
AND vote_type = 'like') AS likes,
(SELECT COUNT(*)
FROM votes
WHERE message_id = m.message_id
AND vote_type = 'dislike') AS dislikes
FROM private_messages m
WHERE 1 #and hidden is null
and recipient_id = 1
ORDER BY datetime DESC
现在要将它们合并到一个查询中,一个额外的参数将显示其私人消息或信用消息。