Visa ett inlägg
Oläst 2013-01-31, 12:14 #12
Conny Westh Conny Westh är inte uppkopplad
Klarade millennium-buggen
 
Reg.datum: Aug 2005
Inlägg: 5 166
Conny Westh Conny Westh är inte uppkopplad
Klarade millennium-buggen
 
Reg.datum: Aug 2005
Inlägg: 5 166
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
Conny Westh är inte uppkopplad   Svara med citatSvara med citat