Det kan ju vara lite smart att lägga upp en StoredProcedure så det blir enkelt att anropa denna procedure om man använder den på fler ställen:
Kod:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ListOfThreadsByLatestUpdate`()
BEGIN
SELECT threadid, MAX(senastedatum) as senastedatum
FROM
(
SELECT threadid, MAX(createddate) AS senastedatum from wn.threads
GROUP BY threadid
UNION
SELECT threadid, MAX(created) AS senastedatum from wn.posts
GROUP BY threadid
) x
GROUP BY threadid
ORDER BY senastedatum DESC;
END