如何在 Java 中使用带有 IN 的 sql 查询作为 select 语句
我需要使用 java 中的 sql 查询,其中包含 IN 子句。我已经看到了当 IN 子句是预先确定的集合时执行此操作的建议,例如在这种情况下不起作用的数字,因为该集合是动态的。这就是我想做的:
select c.cust_name
from cust_acct c, has h
where c.cust_id=h.cust_id
and h.sh_add in (select a.sh_add from address a where sh_st='VA')
我没有遇到任何错误。也就是说,代码运行时我只是没有得到这个特定查询的结果
I need to us a sql query in java that has an IN clause in it. I have seen suggestions for doing this when the IN clause is a predetermined set, such as numbers which won't work in this case because the set will be dynamic. Here is what I am trying to do:
select c.cust_name
from cust_acct c, has h
where c.cust_id=h.cust_id
and h.sh_add in (select a.sh_add from address a where sh_st='VA')
I do not get any faults. That is, the code runs I just get no results for this particular query
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否检查过从
select a.sh_add from address a where sh_st='VA'
获得了正确的中间结果?您可以将查询重写为:
Have you checked that you are getting the right intermediate results from
select a.sh_add from address a where sh_st='VA'
?You could just rewrite the query as: