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)
 One to many problem

Author  Topic 

assiff79
Starting Member

7 Posts

Posted - 2014-03-05 : 12:00:14
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
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-03-05 : 12:11:18
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

7 Posts

Posted - 2014-03-07 : 13:54:15
Thanks for your guidance. this helped ma a lot to solve problem.


asif
Go to Top of Page
   

- Advertisement -