HSQL DB 在查询中不接受 UNION

HSQL DB is not accepting UNION in query

我正在使用 hsql db(v:2.3.6) 并且查询是

select id, name, phone
from person p, address a
where a.id = p.id 
order by id LIMIT 10 

union 

select id, name, phone
from old_person op, old_address oa
where op.id = oa.id
order by id LIMIT 10

但上面的查询抛出错误:

Caused by: org.hsqldb.HsqlException: unexpected token: UNION

我不确定为什么这是个问题。

您的查询旨在在合并 UNION 中的列表之前从 person table 中获取 10 行,从 old_person table 中获取 10 行。为此,您需要在每个 SELECT 查询周围使用括号。

(select id, name, phone
from person p, address a
where a.id = p.id 
order by id LIMIT 10) 

union 

(select id, name, phone
from old_person op, old_address oa
where op.id = oa.id
order by id LIMIT 10)

如果您删除第一个 LIMIT 并保留最后一个,您可能会得到更少的行(也可能是不同的行),因为总限制从 20 减少到 10。