H2中的where() [英] Where() in (select) H2

查看:224
本文介绍了H2中的where()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2种软件(均为Java):一种使用MySSQL,另一种使用H2数据库.我的问题是在MySQL中,我有以下查询:

I have 2 kinds of software (both Java): One with MySSQL and the other with H2 database. My problem is that in MySQL I have this query:

Select * from X where (1,2,3) in (select 4,5,6 from Y)

但是在H2中,抛出此错误:

But in H2 throw me this error:

子查询不是单列查询; SQL语句:

Subquery is not a single column query; SQL statement:

我基本上理解了这是什么意思,但是我需要从X中选择Y中的所有值,并且我读到这是最有效的方法.另一种方法是将Y中的所有值分配给Java对象,然后将其放入X中,但我知道这不是最佳"的方法

I understand basically what this mean but I need to select all values from X that are in Y and I read that this is the most efficient way. The other way could be asign all the values from Y to a Java Object and then put them in to X but I know that this is not the "best" way to do it

推荐答案

尝试将查询修改为具有单个值

Try to modify the query to have single values

Select * from X where CONCAT(1,2,3) in (select CONCAT(4,5,6) from Y)

因此,您有一个3列值都连接在一起的字段,而不是3列

So instead of 3 columns you have one where all the 3 column values are joined

这篇关于H2中的where()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆