I need to us a sql query in 开发者_Python百科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
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:
select c.cust_name
from cust_acct c
inner join has h
on c.cust_id=h.cust_id
inner join address a
on h.sh_add = a.sh_add
where a.sh_st = 'VA'
精彩评论