Linking to detail tables without returning duplicates

,

So this is a case for windowing functions.

What you can do is make a calculated field on your top level like this.

Row_Number() over (partition by JobHead.JobNumber orderby OrderRel.Date)

I guessed at the fields, but you should get the picture.

Then in your subquery criteria on the top level (or whatever level you are doing this), filter to only show the rows where that field is 1. This will drop off the duplicates rows.

Let me know if that doesn’t make sense, or you need more help.

Also, I didn’t open your query to see what you were doing… so if I’m wildly off, let me know.

2 Likes