Code:
...
TableA a
LEFT OUTER JOIN
TableB b
ON a.value = 31
AND b.key = a.key
As a basic rule,
ON condition in outer join gives selection condition of rows from inner table(I mean right table of left outer join or left table of right outer join),
even if the condition includes columns of outer table(left table of left outer join or right table of right outer join).
For example:
the following query joins all rows of TableB to a row of TableA which satisfied the (ON) condition "a.value = 31".
Code:
------------------------------ Commands Entered ------------------------------
WITH TableA(Key , value) AS (
VALUES
(100 , 31)
, (102 , 23)
)
, TableB(Key , M_Value) AS (
VALUES
(100 , '1A105')
, (101 , '1A153')
)
SELECT a.key AS a_key
, a.value
, b.key AS b_key
, b.m_value
FROM TableA a
LEFT OUTER JOIN
TableB b
ON a.value = 31
/* AND b.key = a.key */
-- WHERE a.key = 101
;
------------------------------------------------------------------------------
A_KEY VALUE B_KEY M_VALUE
----------- ----------- ----------- -------
100 31 100 1A105
100 31 101 1A153
102 23 - -
3 record(s) selected.