Home » SQL & PL/SQL » SQL & PL/SQL » LEFT JOIN _last_ of matchin entries
LEFT JOIN _last_ of matchin entries [message #446741] Wed, 10 March 2010 04:20 Go to next message
mrQQ
Messages: 1
Registered: March 2010
Junior Member
Hello,

I have this table:

EntryNo
Date
TypeID

I also have this table

StartDate
EndDate
TypeID
TypeCode

The entries in the second table overlap, for any given time moment there can be more than one matching entry.

I need to join second table to the first one, but take only the last of matching records.

If the entries wouldnt overlap, I could do a left join on StartDate <= Date AND EndDate >= Date AND TypeID=TypeID. But in this case, this would duplicate records.

So how do I do this? Sad
Re: LEFT JOIN _last_ of matchin entries [message #446743 is a reply to message #446741] Wed, 10 March 2010 04:24 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Provide properly working test case with original and expected output.

regards,
Delna
Re: LEFT JOIN _last_ of matchin entries [message #446745 is a reply to message #446741] Wed, 10 March 2010 04:24 Go to previous message
Michel Cadot
Messages: 68733
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
If you post a working Test case: create table and insert statements along with the result you want with these data then we will work with your table and data.

Before please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version with 4 decimals.

Regards
Michel
Previous Topic: CURSOR in ORACLE
Next Topic: Which query would execute quickest
Goto Forum:
  


Current Time: Tue Feb 11 13:02:18 CST 2025