Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
12-06-2006, 02:48 AM #1
- Join Date
- Dec 2006
- Thanked 0 Times in 0 Posts
sql server 2005. need help with query statement
how can this statement be change from a MySql query to sql server 2005 query?
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
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
Last edited by xwarrior; 12-06-2006 at 02:56 AM.
12-07-2006, 10:15 AM #2
- Join Date
- Jun 2002
- Zwolle, The Netherlands
- Thanked 31 Times in 31 Posts
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) )I am the luckiest man in the world