Prehistory
It seems there are plenty of similar questions on the forum, but for some reason they did not help me.
I want to make a list of 50 fresh (not earlier than a month ago) answers (new subscribers, likes, comments) for social, forgive me Zuckerberg, networks.
That is, you need to combine 3 tables to simultaneously select a maximum of 50 rows from them and sort these rows by dateTime. That's all what my brain was capable of:
$getReplies=$pdo->prepare( "SELECT * FROM followers FULL OUTER JOIN comments ON comments.replyToUserId = :id AND comments.dateTime BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW() FULL OUTER JOIN likes ON likes.toId = :id AND likes.dateTime BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW() WHERE followers.toId = :id AND followers.dateTime BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW() ORDER BY followers.dateTime DESC, comments.dateTime DESC, likes.dateTime DESC LIMIT 50" ); $getReplies->execute(array('id' => $out[0])); $replies=$getReplies->fetchAll(); But the output is nothing. Help, please, I already danced all tambourine.
▼ AT THE MOMENT THE PROBLEM IS SUCH ▼
On the advice below, I did it with the help of UNION. But I still get an empty array, even for the simplest queries that work without problems one by one. What could be wrong here?
$getReplies=$pdo->prepare(" SELECT * FROM followers WHERE toId = '1' UNION SELECT * FROM likes WHERE toId = '1' "); $getReplies->execute(); $replies=$getReplies->fetchAll();
FULL OUTER JOINin MySQL is not in principle. Something tells me that you needUNION- Mike*bad tone, always specify the necessary columns - Mike