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.

Ben
  • 51,770
  • 36
  • 127
  • 149
Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191

1 Answers1

0

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)
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
Mr Bear
  • 26
  • 3