Recently I came up with the scenario where I have two tables named emp1 and emp2 and it has following columns and table looks like below
You need to join the two tables, then use the
greatest() function to return the bigger of the two values.
As the salary can be
null you need to take that into account using the
select t1.dno, greatest(coalesce(t1.sal,0), coalesce(t2.sal,0)) as sal from emp1 t1 join emp2 t2 on t1.dno = t2.dno;
SQLFiddle example: http://sqlfiddle.com/#!15/bca1b/1