sybaseansi-sql

rewrite old sql but result of two sql is not the same


I want to rewrite old sql

select * from a, b, c where a.columnA = b.columnB and a.columnC *= c.columnD and a.columnE *= c.columnF

I tried as below

select * from a join b on a.columnA = b.columnB left join c on a.columnC = c.columnD left join c on a.columnE = c.columnF

but result of two sql is not the same. Please help.


Solution

  • Combine the two left join columns into a single left join clause, eg:

    select * 
    from   a
    
    join   b 
    on     a.columnA = b.columnB
    
    left
    join   c 
    on     a.columnC = c.columnD
    and    a.columnE = c.columnF