Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. SELECT
  2. CONCAT(t.topicID,'') AS topicID,
  3. CONCAT(t.userID,'') AS authorID,
  4. CONCAT(t.topicName,'') AS topicName,
  5. CONCAT(t.DATE,'') AS topicDate,
  6. CONCAT(u.login,'') AS topicAuthor,
  7. COUNT(DISTINCT r.replyID) AS postCount,
  8. CONCAT(u2.login,'') AS lastUser,
  9. CONCAT(r2.DATE, '') AS lastDate
  10. FROM Topics AS t,
  11. Users AS u,
  12. Reply AS r,
  13. Users AS u2,
  14. Reply AS r2
  15. WHERE t.userID = u.userID AND
  16. t.topicID = r.topicID AND
  17. t.topicID = r2.topicID AND
  18. u2.userID = r2.userID AND
  19. r2.replyID =
  20. (
  21. SELECT MAX(r3.replyID)
  22. FROM Reply r3
  23. WHERE r3.topicID = t.topicID
  24. )
  25. GROUP BY topicID
  26. ORDER BY r2.DATE DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement