Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 join two tablw with max values

Author  Topic 

asifbhura
Posting Yak Master

165 Posts

Posted - 2013-04-18 : 02:51:10
Hello

I have two tables one which contains member information.

while other contains renewal information which can be more than one records.

I have autoID which creates automatically in second table

and both tables are joined with memid

now I want to join 2 table but information from second table must get only last inserted records

what should be query ?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-18 : 02:57:29
[code]
SELECT *
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY m.memid ORDER BY autoID DESC) AS Rn,*
FROM Member m
INNER JOIN Renewal r
ON r.memid = m.memid
)t
WHERE Rn=1
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -