SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 join two tablw with max values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

asifbhura
Posting Yak Master

India
165 Posts

Posted - 04/18/2013 :  02:51:10  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 04/18/2013 :  02:57:29  Show Profile  Reply with Quote

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


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000