【问题标题】:HSQL DB is not accepting UNION in queryHSQL DB 在查询中不接受 UNION
【发布时间】:2021-09-01 12:42:44
【问题描述】:

我正在使用 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.hsqldb.HsqlException:意外令牌:UNION

我不知道为什么这是个问题。

【问题讨论】:

    标签: hsqldb


    【解决方案1】:

    在合并 UNION 中的列表之前,您的查询旨在从 person 表中获取 10 行,并从 old_person 表中获取 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,您可能会获得更少的行(也可能是不同的行)。

    【讨论】:

      猜你喜欢
      • 2017-08-04
      • 1970-01-01
      • 2014-09-14
      • 1970-01-01
      • 1970-01-01
      • 2012-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多