salvationishere
salvationishere

Reputation: 3511

sql query to retrieve DISTINCT rows on left join

I am developing a t-sql query to return left join of two tables, but when I just select records from Table A, it gives me only 2 records. The problem though is when I left join it Table B, it gives me 4 records. How can I reduce this to just 2 records?

One problem though is that I am only aware of one PK/FK to link these two tables.

Upvotes: 0

Views: 722

Answers (2)

Eric Frick
Eric Frick

Reputation: 857

Remember that the left join brings you null fields from joined table. Also you can use select(distinct), but i can't see well you issue. Can you give us more details?

Upvotes: 0

L-Note
L-Note

Reputation: 2006

The field you are using for the join must exist more than once in table B - this is why multiple rows are being returned in the join. In order to reduce the row count you will have to either add further fields to the join, or add a where clause to filter out rows not required.

Alternatively you could use a GROUP BY statement to group the rows up, but this may not be what you need.

Upvotes: 2

Related Questions