0

When I execute the below query on Microsoft SQL Server 2012, I get values which are not present in the table RequiredVisitLink. Why is this happening? I was expecting to get values only common to both and which satisfy the condition.

select a.ID from table1 a left join table2 b on a.ID = b.ID where Baseball=1
tubby
  • 2,074
  • 3
  • 33
  • 55

2 Answers2

2

Try to use inner join instead of left join

select a.ID from table1 a inner join table2 b on a.ID = b.ID where Baseball=1

The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.

The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match.

Discern
  • 183
  • 2
  • 9
-1

instead left join, try

Left Outer join

Right Outer join

Inner join

Community
  • 1
  • 1
Kevin mtk
  • 253
  • 1
  • 2
  • 11