我要向我的SQL提出复杂的问题。 如果工会的第一部分无效,我想宣布无效;否则,我要回去工会的结果。 例:
IF( select * (select * from t1) as result, result UNION (select * from t2), "");
我的法典行不通。 我有以下错误:
Operand should contain 14 column(s)
是否有任何想法来纠正这种情况?
Thanks for the first reply below but it looks too expensive:
(SELECT * FROM t1)
UNION
( SELECT * FROM t2
WHERE EXISTS
( SELECT * FROM t1 )
)
My reason is t1 is actually a bunch of UNIONed statements itself. Is there a way to use something similar to an alias? The example below failed because the alias "result" is not carried across the UNION keyword.
SELECT * FROM ( large compound select statement) AS result UNION ( SELECT * FROM t2 WHERE EXISTS ( SELECT 1 FROM result ) )
感谢。