Given:
t1{id,type}
t2{type,table1_id}
I'm using this:
SELECT IF(t1.type IS NULL, 'some default', t1.type) as ret from t1
I want to do something like this:
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
This --
SELECT IF(
t1.type IS NULL,
IF(
(SELECT t2.type FROM t2
WHERE t2.table1_id=t1.id LIMIT 1)
IS NOT NULL,
t2.type,
'some defaults'),
t1.type
) as ret from t1, t2 where t1.id = t2.table1_id
seems to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With