Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Join on Most Recent Record

Posted on 2007-11-20
3
Medium Priority
?
913 Views
Last Modified: 2010-05-18
I have two tables in SQL, table one has information, and table two has more dynamic information that is related to table one.  

Table1
ID
LRSN
INFO
MOREINFO

Table 2
ID
LRSN
DESCRIPTION
LAST_UPDATE

I would like to join the two tables on LRSN, and pull the Description of the most recent Last_Update record from table two.  Can someone help me out with this relationship?  Thanks in advance for the help!
0
Comment
Question by:jayh99
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 20319619
select ...
from table1 t1
join table2 t2
  on t1.lrsn = t2.lrsn
 and t2.last_update = ( select max(i.last_update) from table2 i where i.lrsn = t2.lrsn )
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20319625
SELECT *
FROM Table1 t1
INNER JOIN Table2 t2 ON t1.LRSN = t2.Lrsn
WHERE T2.Last_Update = (SELECT MAx(last_update) from tabel2 where lrsn = t2.lrsn)
0
 
LVL 1

Author Closing Comment

by:jayh99
ID: 31410115
Excellent!  Thanks for the quick response!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question