I have two type of message, one is private message and another is credit message are inserting into two different table. Now I'm trying to fetch the data.
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
and
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
Now want to merge them into one query one extra parameter will show its private message or credit message.
See Question&Answers more detail:os