我使用的是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
但上面的查询抛出了一个错误:
由:org.sqldb.HsqlException引起:意外的令牌:UNION
我不确定为什么这是一个问题。
在UNION中合并列表之前,您的查询旨在从person
表中获得10行,从old_person
表中获得十行。为此,您需要在每个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并保留最后一个LIMIT,那么随着总限制从20减少到10,您可能会得到更少的行(也可能是不同的行(。