TygerTyger
02-13-2009, 02:30 PM
What I want to do is retrieve a list of all the original texts by user 1 and also the latest version of the text. The table is in the format below.
VARNAME TEXT USER TIME
test Testing 1 100000000
test Update 2 110000000
test Updated 3 120000000
test UPDATE 2 130000000
So one row would get the text "Testing" and "UPDATE". I'm sure it is simple but I can't quite get it.
I've managed the query for just the last text...
SELECT varname, text, time, MAX(time) as maxtime
FROM texts
WHERE user != 1
GROUP BY varname
HAVING time = maxtime
... but have failed to get it working as part of the larger query.
VARNAME TEXT USER TIME
test Testing 1 100000000
test Update 2 110000000
test Updated 3 120000000
test UPDATE 2 130000000
So one row would get the text "Testing" and "UPDATE". I'm sure it is simple but I can't quite get it.
I've managed the query for just the last text...
SELECT varname, text, time, MAX(time) as maxtime
FROM texts
WHERE user != 1
GROUP BY varname
HAVING time = maxtime
... but have failed to get it working as part of the larger query.