鉴于:
t1{id,type}
t2{type,table1_id}
我正在使用这个:
SELECT IF(t1.type IS NULL, 'some default', t1.type) as ret from t1
我想做这样的事情:
SELECT IF(
t1.type IS NULL,
IF(
(SELECT t2.type FROM t2 WHERE t2.table1_id=t1.id LIMIT 1) IS NOT NULL,
table2.type,
'some defaults'
),
t1.type
) as ret from table1