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
More Related Contents:
- Select rows which are not present in other table
- Left Join With Where Clause
- Two SQL LEFT JOINS produce incorrect result
- SQL to LINQ with multiple join, count and left join
- dplyr left_join by less than, greater than condition
- Difference between left join and right join in SQL Server [duplicate]
- Query with LEFT JOIN not returning rows for count of 0
- Are “from Table1 left join Table2” and “from Table2 right join Table1” interchangeable?
- Why and when a LEFT JOIN with condition in WHERE clause is not equivalent to the same LEFT JOIN in ON? [duplicate]
- Explain JOIN vs. LEFT JOIN and WHERE condition performance suggestion in more detail
- Difference between RIGHT & LEFT JOIN vs RIGHT & LEFT OUTER JOIN in SQL [duplicate]
- SQL SELECT from multiple tables
- SQL Oracle LEFT JOIN and SUBQUERY error: ORA-00905: missing keyword
- Select first record in a One-to-Many relation using left join
- Get Parent with multiple children in desc order
- How can I schedule a job to run a SQL query daily?
- Convert Month Number to Month Name Function in SQL
- How do I do top 1 in Oracle? [duplicate]
- Delete from two tables in one query
- Removing leading zeroes from a field in a SQL statement
- Concatenate multiple result rows of one column into one, group by another column [duplicate]
- sql ORDER BY multiple values in specific order?
- ColdFusion adding extra quotes when constructing database queries in strings
- NOT NULL constraint over a set of columns
- Dynamic Pivot Table in SQL Server
- How can I determine the status of a job?
- How can I select rows with most recent timestamp for each key value?
- postgresql – sql – count of `true` values
- Is it possible to execute a text file from SQL query?
- SELECT query with CASE condition and SUM()