Hvis de eksisterende forespørgsler gør, hvad du ønsker/har brug for, UNION
vil gøre det ret nemt at kombinere dem, sådan noget som;
SELECT * FROM (
SELECT is_private 0, <field1>,<field2>,<field3>, ... ,(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
UNION ALL
SELECT 1, <field1>, <field2>, <field3>, ... ,(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
Bemærk, at du skal vælge samme antal/rækkefølge af kolonner fra begge forespørgsler, for at fagforeningen fungerer. SELECT *
gør det svært at kontrollere, om/det er tilfældet. Hvis