这是mi查询
with r as (
select id, created_at from table1 ta
)
select * from r
union all
select id, created_at from table2 tb where confirmed_at IS null ORDER BY id DESC LIMIT 1
and not exists (
select * from r
)
,响应为 SQL错误[42804]:错误:AND的参数必须为布尔型,而不是整数 位置:203
答案 0 :(得分:1)
似乎仅在前半部分为空的情况下才想从联合的后半部分返回记录。这是一种方法:
WITH r AS (
SELECT id, created_at FROM table1
)
SELECT id, created_at FROM r
UNION ALL
SELECT id, created_at
FROM table2
WHERE confirmed_at IS NULL AND (SELECT COUNT(*) FROM r) = 0
ORDER BY id DESC
LIMIT 1;