Home Forums SQL Server 2012 SQL Server 2012 - T-SQL Selecting alternative value if one row(possible two) doesnt exist in reference table RE: Selecting alternative value if one row(possible two) doesnt exist in reference table

  • got a brain wave , maybe there is better way of doing this but this looks like its working for me

    SELECT b.value, a.productname

    FROM b RIGHT OUTER JOIN

    a ON b.id = a.id

    where b.flag=(select max(b.flag) from b

    RIGHT OUTER JOIN

    a ON b.id = a.id)

    GROUP BY b.value, a.productname