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)
 One to many problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

assiff79
Starting Member

Pakistan
7 Posts

Posted - 03/05/2014 :  12:00:14  Show Profile  Reply with Quote
hi,
i have two table one for customers and other table for thier debit credit, totals. there exist foriegn key relationship between these two tables. Now problem is that i want last record in 2nd table for each user in 1st one.

asif

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 03/05/2014 :  12:11:18  Show Profile  Reply with Quote
It really helps if you post your table schema and sample data. See the link below for how to do that. Here is one way you might go about getting those results:
SELECT
	*
FROM
	(
		SELECT
			*
			,ROW_NUMBER() OVER (PARTITION BY Customer.ParitionColumn ORDER BY DebitCard.DateColumn DESC) AS RowNum
		FROM
			Customer
		INNER JOIN
			DebitCard
			ON Customer.ID = DebitCard.CustomerID
	) AS T
WHERE
	T.RowNum = 1


http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

assiff79
Starting Member

Pakistan
7 Posts

Posted - 03/07/2014 :  13:54:15  Show Profile  Reply with Quote
Thanks for your guidance. this helped ma a lot to solve problem.


asif
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.12 seconds. Powered By: Snitz Forums 2000