Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by zebediah49 for Making a user profile activity feed

JOIN. It seems you know that, but here's how: SELECT * FROM comments LEFT JOIN users ON comments.user_id = users.id

Thus, as far as I can tell, you're trying to order two separate things at the same time. The closest I think I can come up with would be something like:

(SELECT comments.date AS date, users.username AS name, comments.url AS url CONCAT('Something happened: ',comments.url) AS text     FROM comments LEFT JOIN users ON comments.user_id = users.id     WHERE users.id = %s)UNION(SELECT ratings.date AS date, users.username AS name, ratings.url AS url CONCAT('Something happened: ',ratings.url) AS text    FROM comments LEFT JOIN users ON comments.user_id = users.id     WHERE users.id = %s)ORDER BY date DESC LIMIT 0,10

Note that the columns of both parts of the union match up. I'm pretty sure that that is required for something like this to work. That's why I have that CONCAT statement, which lets you build a string that works differently between ratings and comments.


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>