I have two tables,mycode and mycode1
The two tables contain same field CODE and img. I need to insert the table2 to table 1 two tables. Both of them contain the same code numbers in CODE field.
eg: table 1
CODE img
110 null
111 null
112 image3.jpg
table 2
CODE img
110 imag1.jpg
111 image2.jpg
I need the output as
table2
CODE img
110 imag1.jpg
111 image2.jpg
112 image3.jpg

Pradeep ShetRank #595 · 4K reputationPosted Jan 14, 2015, 6:40 AM EST
This can be done as below
SELECT CODE, COALESCE(t1.img,t2.img) AS img
FROM table1 t1
INNER JOIN table2 t2 ON t1.Code = t2.Code
This will give you the desired output. Mark it as answered if it helped you.
vishnu suresh53 reputationPosted Jan 14, 2015, 7:24 PM EST
select CODE, COALESCE(t1.img,t2.img) AS img
FROM newcode t1
INNER JOIN Mycode6 t2 ON t1.CODE= t2.CODE