Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Join on Most Recent Record

Posted on 2007-11-20
3
Medium Priority
?
903 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

721 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