LEFT JOIN a table to a query where the query has a literal in the SELECT clause will replicate the literal for non joined records.
Table1 |
| ||||||||||||||||||||
Table2 |
| ||||||||||||||||||||
Query1 Introduce a literal. SELECT Key, "XYZ" AS myLit, myNum FROM Table2; |
| ||||||||||||||||||||
Query2 The bug. SELECT Table1.Key, myText, myNum, myLit FROM Table1 LEFT JOIN Query1 ON Table1.Key=Query1.Key; |
| ||||||||||||||||||||
Query3 The fix. SELECT DISTINCT * FROM Query1 WHERE myLit="XYZ"; |
| ||||||||||||||||||||
Query4 Bug Free! SELECT Table1.Key, myText, myNum, myLit FROM Table1 LEFT JOIN Query3 ON Table1.Key=Query3.Key; |
|
No comments:
Post a Comment