travisbrown
Technical User
- Dec 31, 2001
- 1,016
Okay, maybe there is a simple way to do this that I'm overlooking.
I need to join two table, but only return the first record on the right table where there may be many. Sort of a semijoin, I guess, but returning the matching record too.
I've tried a bunch of things, but am not getting very far. Before doing some inelegant ASP scripting, is there a way to do this in SQL? Here's my starting query that returns the one to many records. SCHED is the parent table, SEG is the child.
I need to join two table, but only return the first record on the right table where there may be many. Sort of a semijoin, I guess, but returning the matching record too.
I've tried a bunch of things, but am not getting very far. Before doing some inelegant ASP scripting, is there a way to do this in SQL? Here's my starting query that returns the one to many records. SCHED is the parent table, SEG is the child.
Code:
SELECT
SCHED.SCHD_ID,
SEG.START_DTE,
SCHED.ACT_CPNT_ID, SCHED.SCHD_DESC,
SCHED.CANCELLED,
SCHED.NOTACTIVE
FROM PLATEAU.PA_SCHED SCHED LEFT OUTER JOIN PLATEAU.PA_SCH_SEG SEG ON SEG.SCHD_ID = SCHED.SCHD_ID
WHERE (SEG.START_DTE BETWEEN '01-July-2008' AND '01-August-2008') ORDER BY SEG.START_DTE ASC