如果一個值value_two
不存在(或null
)table_two
我想要默認值value_two
table_one
。從存在價值的表中選擇?
我有以下查詢格式:
SELECT one.value_one, two.value_two
FROM schema.table_one one
LEFT JOIN schema.table_two two
ON one.id_value = two.id_value and two.other_column = 'other_val'
WHERE one.id_value = 'id_val';
我知道有一個選項是選擇價值所有和返回後處理它在客戶端執行以下操作:
SELECT one.value_one, one.value_two, two.value_two as two_value_two
FROM schema.table_one one
LEFT JOIN schema.table_two two
ON one.id_value = two.id_value and two.other_column = 'other_val'
WHERE one.id_value = 'id_val';
是否有'乾淨'的方式檢查two.value_two
是否存在,如果不存在則默認選擇one.value_two
?