LEFT JOIN query not returning all rows in first table

前端 未结 1 474
无人及你
无人及你 2020-12-07 06:27

Using management studio for SQL Server 2008 R2.

Trying to do a LEFT JOIN and I need to return all rows from the first table regardless of t

相关标签:
1条回答
  • 2020-12-07 06:56

    Move the b condition from WHERE to ON to get a real LEFT JOIN. (With the b condition in the WHERE clause, it executes as a regular inner join...)

    select a.id, a.name, b.store, b.stock
    from products a left join stock b
      on a.id = b.id and b.store = '001'
    order by a.id
    
    0 讨论(0)
提交回复
热议问题