I have a long sql query that, among other things, accesses multiple tables with an inner join and some left outer joins. I am expecting it to give a single set of results but when it finds more than one result from the left outer join, it duplicates the results. So, code is basically:
What happens is if there are no rommates, everything works well but if there are any rommates, I get the right query results but it sends the data more than one time instead of just a single result with all the data populated (the results are sent to a work file to print). So, instead of sending something like name, rommate1, roommate2, roommate3 I get name, rommate1 and then name, roommate1, and then name, roommate2, etc so I get 3x results.
Thanks, Brad
Code:
Select tenant.name, r1.roommate, r2.roommate, r3.roommate from Property Inner Join Tenant on tenant.property = property.property left outer join room r1 on r1.code = property.code left outer join room r2 on r2.code = property.code and r2.code <> r1.code left outer join room r3 on r3.code = property.code and r3.code <> r1.code and r3.code <> r2.code
Thanks, Brad
Comment