473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

First Record Join

2
I need to join two tables. The First Table Has a ClientID and an Evaluation Date.
The Second Table is a Many-to-One relationship and Has the ClientID and a Effective Date. What I want is a join of the First and Second Table where I only get the first record in the Second Table where Effective Date is Less than or equal to the Evaluation Date.

Table 1:
Client1, 2006-12-31
Client2, 2007-01-10
Client3, 2006-10-20

Table 2:
Client1, 2007-01-08
Client1, 2006-12-31
Client1, 2006-11-30
Client2, 2007-01-12
Client2, 2006-12-20
Client2, 2006-11-11
Client3, 2007-01-08

Results:
Client1, 2006-12-31, Client1, 2006-12-31
Client2, 2007-01-10, Client2, 2006-12-20
Client3, 2006-10-20, Null, Null

Thanks for your help
Jan 15 '07 #1
3 1556
MMcCarthy
14,534 Expert Mod 8TB
I need to join two tables. The First Table Has a ClientID and an Evaluation Date.
The Second Table is a Many-to-One relationship and Has the ClientID and a Effective Date. What I want is a join of the First and Second Table where I only get the first record in the Second Table where Effective Date is Less than or equal to the Evaluation Date.

Table 1:
Client1, 2006-12-31
Client2, 2007-01-10
Client3, 2006-10-20

Table 2:
Client1, 2007-01-08
Client1, 2006-12-31
Client1, 2006-11-30
Client2, 2007-01-12
Client2, 2006-12-20
Client2, 2006-11-11
Client3, 2007-01-08

Results:
Client1, 2006-12-31, Client1, 2006-12-31
Client2, 2007-01-10, Client2, 2006-12-20
Client3, 2006-10-20, Null, Null

Thanks for your help
Please post the SQL of the query you are currently using.
Jan 15 '07 #2
scmhc
2
he code so far is as follows:

SELECT [PERF - from Tier (Modified)].CLIENTID,
[PERF - from Tier (Modified)].SITEID,
[PERF - from Tier (Modified)].PURPEVAL,
[PERF - from Tier (Modified)].EVALDATE,
[PERF - from Tier (Modified)].INITEVADA,
[PERF - PurpEval 01 All].EVALDATE

FROM [PERF - from Tier (Modified)] INNER JOIN [PERF - PurpEval 01 All]
ON ([PERF - from Tier (Modified)].SITEID = [PERF - PurpEval 01 All].SITEID) AND
([PERF - from Tier (Modified)].CLIENTID = [PERF - PurpEval 01 All].CLIENTID)

WHERE ((([PERF - PurpEval 01 All].EVALDATE)<=[PERF - from Tier (Modified)]![EVALDATE]));


This gives me all records with date <= Modified evaldate
I ONLY WANT THE FIRST RECORD <= Modified evaldate
Jan 15 '07 #3
NeoPa
32,556 Expert Mod 16PB
Try this as a basis :
Expand|Select|Wrap|Line Numbers
  1. SELECT T1.ClientID,
  2.        T1.EvaluationDate,
  3.        Min(T2.EffectiveDate) AS MinEffDate
  4. FROM Table1 AS T1 LEFT JOIN Table2 AS T2
  5.   ON T1.ClientID=T2.ClientID
  6. WHERE T2.EffectiveDate<T1.EvaluationDate
  7. GROUP BY T1.ClientID
Jan 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: yvan | last post by:
Approximately once a month, a client of ours sends us a bunch of comma-delimited text files which I have to clean up and then import into their MS SQL database. All last week, I was using a Cold...
4
by: KJ | last post by:
We use a third party software package for acctg that limits us on field size - as a result, we at times have to enter an item into the app multiple times in order to get all the information. I...
4
by: CK | last post by:
Good Morning, I have a person table with personID. I have a personRate table with personID, rateID, and effectiveDate. I need to select fields from personRate, but I want the fields from the...
4
by: Larry | last post by:
OK, I'm just learning MySQL, or at least trying to. I have a table with data as follows USER FIELDID VALUE 1 1 Bob 1 2 Smith 2 1 John 2 ...
4
by: peashoe | last post by:
I get the following error: ADODB.Field error '80020009' Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. This is my code: ' Get...
13
by: Bart | last post by:
Hi, i get the error: "There is already an open DataReader associated with this Command which must be closed first" Thanks Bart ----------------------------------------- Imports...
3
by: Phil Stanton | last post by:
I have a form based on a complex query (Lots of tables) If I delete a record, everything appears to be OK. Get the message "Youa are about to delete 1 record ....". I say yes. The record count...
1
by: Paul H | last post by:
I have an Employees table with the following fields: EmployeeID SupervisorID Fred Bob Bob John Bob Mary Bill Bill I have created a self join in...
12
by: Phillip B Oldham | last post by:
I'm keen on learning python, with a heavy lean on doing things the "pythonic" way, so threw the following script together in a few hours as a first-attempt in programming python. I'd like the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.