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.

有帮助吗?

解决方案

The sub-query will only be executed if col1 is null but each time it is null. So if there are many null values in col1 this will become very slow.

The following may work better for you:

select coalesce(col1,col2) from table1,table2 
                     where (relationship between both tables)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top