...

sql server 2005. need help with query statement

xwarrior
12-06-2006, 02:48 AM
how can this statement be change from a MySql query to sql server 2005 query?

SELECT
DISTINCT
TagID,
x,
y
from RTLOC
where TDate =
(SELECT max(my.TDate) from RTLOC as my
and TagID = my.TagID)



i have 4 fields, TagID, x,y,Tdate.
tag1, 123,523, date
tag1, 123, 123, latest date
tag2, 434,423, latest date
tag2, 123,432, date
tag3,342, 543,date
tag3,532,342,latest date

in the TagID field i have different names. i want to use a query statement to draw the x and Y of each different TagID by the latest TDate.

expected result should be TagID , x , y , TDate
tag1 ,123 ,123 ,latest date
tag2 ,434 ,423 ,latest date
tag3 ,532, 342 , latest date

Roelf
12-07-2006, 10:15 AM
You were almost there, the AND in the subquery and the lack of alias for the first RTLOC were wrong.

Here is a query that works:
SELECT DISTINCT TagID, x, y
FROM RTLOC rt1
WHERE (Tdate =
(SELECT MAX(rt2.TDate)
FROM RTLOC rt2
WHERE rt1.TagID = rt2.TagID)
)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum