0
select IFNULL(col1, (select col2 from table2 where ...)) from table1 

Will it run select for table2 if table1 would have not null value? This is a speed issue question. I have no appropriate database to check.

4

1 回答 1

0

只有当 col1 为 null 但每次都为 null 时,才会执行子查询。因此,如果 col1 中有许多空值,这将变得非常慢。

以下可能更适合您:

select coalesce(col1,col2) from table1,table2 
                     where (relationship between both tables)
于 2017-01-11T01:45:44.217 回答