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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 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
52326 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  
 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.34 seconds. Powered By: Snitz Forums 2000