I had this requirement where I had TableA and TableB where I need to update a field FieldA in TableA with the value in TableB for matching records based on FieldB. If there are no matching records then I need to update the same with 0. And the fieldB based on which I have to match the records in two tables are in two different formats(TableA -Char, TableB - Int) After figuring out that Left Out Join is the best option to solve this problem I wrote this query.
Select IFNULL(B.FieldB,0)B.FieldB from TableA A
Left Outer Join TableB B On int(A.FieldB) = B.FieldB
But on running the query i found that only the matching records from TableB were getting selected. The Left Outer Join behaved just like an Inner Join.
Finally It worked only when i wrote a subquery first to convert the FieldB in TableA and then used that table to do an Outer Join with TableB.
No comments:
Post a Comment