mysql - obtener las últimas actividades de un usuario

This answer did work but with a problem. User recent activities - PHP MySql

My query is same as that

(SELECT `user_id`, `date_added`, 'vote' AS `type` FROM `vote` WHERE `user_id` = uid) UNION
 (SELECT `user_id`, `date_added`, 'discussion' AS `type` FROM `discussion` WHERE `user_id` = uid) UNION
 (SELECT `user_id`, `date_added`, 'comment' AS `type` FROM `comments` WHERE `user_id` = uid)
 ORDER BY `date_added` DESC;

my tables are votes, comments, discussions. using this query, I cant get the newly inserted ones, but i get is last - 1 actvity. how do I take those in to those query?

preguntado el 27 de noviembre de 13 a las 06:11

can you clarify what you want to get exactly? -

I cant get the newly inserted ones, but i get is last - 1 actvity -

2 Respuestas

Prueba esta

SELECT V.user_id, V.date_added, V.vote
FROM vote AS V 
JOIN discussion AS D ON D.user_id=V.user_id
JOIN comments AS C ON C.user_id=V.user_id
ORDER BY V.date_added DESC

respondido 27 nov., 13:06

Great! I'm glad you figured it out - Diana

You didn't provide a sample data point for us to look at but I think the problem could be that UNION is removing duplicates and your data points may be same across multiple tables? I'm just making a guess here based on the limited information.

I would suggest using Union ALL instead of UNION and see what data you get back. You can read more about Union and UNION All aquí

¡Gracias!

respondido 27 nov., 13:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.