I'm trying to combine data using a Join on two tables (Contributions and PA_Contributions). Both use keys (contactID). I'm selecting everything from the Contributions table but only need to use 2 columns from the other table, PA_Contribution. (tributename and tributedescription).
The problem is that the results are pulling every row from the PA_Contributions table and I only need the data (if any) from those two columns (tributename and tributedescription) based on the contactID pulled to the same row as everything else from the Contribution table.
I believe the problem is the one-to-many issue where there are multiple rows of data for a particular contactID in the 2nd table, and I only need to pull those two columns if there is data in them.
SELECT Contribution.Firstname, Contributions.Lastname, Contributions.Address1, Contributions.Address2, Contribution.City, Contribution.name, Contribution.Amount PA_Contribution.tributenam
FROM Contribution RIGHT OUTER JOIN
PA_Contribution ON Contributions.ContactId = PA_Contribution.pa_contact
WHERE (Contribution.createdon >= @MinDate) AND (Contribution.createdon <= @MaxDate)
ORDER BY Contributions.LastName
I have tried everything from using DISTINCT, Left and Right Outer joins.
As you can see from the screen shot, I'm getting duplicate rows because it's finding mulitple entries in the PA_Contribution table. I only need one tributedescription cloumn for each one. Keep in mind that not all will have data in the tributedescription column, but I need those that do.
Hope that made sense.