Sql COALESCE entire rows?

前端 未结 4 1918
南笙
南笙 2021-01-18 08:21

I just learned about COALESCE and I\'m wondering if it\'s possible to COALESCE an entire row of data between two tables? If not, what\'s the best approach to the following r

4条回答
  •  不思量自难忘°
    2021-01-18 08:42

    You can also do this:

    1) Outer Join the two tables on tbl_Employees.Id = tbl_Customers.Id. This will give you all the rows from tbl_Employees and leave the tbl_Customers columns null if there is no matching row.

    2) Use CASE WHEN to select either the tbl_Employees column or tbl_Customers column, based on whether tbl_Customers.Id IS NULL, like this:

    CASE WHEN tbl_Customers.Id IS NULL THEN tbl_Employees.Name ELSE tbl_Customers.Name END AS Name
    

    (My syntax might not be perfect there, but the technique is sound).

提交回复
热议问题