Skip to content
Advertisement

Select Min Date value from subquery to main query

I’m trying to get the min Date value as a column in the main query where the main query & the subquery have inner joins & the min Date value is dependent on grouping of 3 columns from the main query joins

I tried subqueries in the main query Select statement but they only execute once as my research showed. I’ve tried various ways of joins but can’t get either the logic or the syntax to work. I’m thinking a combination of cte may work but haven’t been able to fathom it out (still a bit too new to these advanced queries for an old dog learning new tricks)

This that I have so far gives me the Comp_Date of each row. What I need to achieve so I can use the data elsewhere later in my program is

So I have all the rows where either Ptsmale or PtsFemale but the min Date Value PtsFirstRec is the earliest date of the pairing grouped also by E.StylID

Advertisement

Answer

This is another window function one:

If you included your test data we’d be able to make sure the code actually works obviously. But it should be something along these lines.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement