views:

82

answers:

3

This is the question about JDBC. I have next task. I'm iterating through rows from table A and for some current row I want to execute some query against table B in context of current row from A. For example, if I have some query like

SELECT B.description FROM A LEFT JOIN B ON A.ID = B.refId

then I want to get all results where B.refId="current row from A".ID. Please, note that I cannot modify query for selecting results from B.

For example, let's table A like this:

ID name

1  nameA
2  nameB

and table B:

ID description refID

1  desc1       1
2  desc2       1
3  decs3       2
4  desc4       2

So if I for example on row from table A with ID 2 and perform my query then I want to get "desc3" and "desc4" only.

I suggest that this task can be solved with cursors but I'm familiar with it. Can anyone give me a hint?

A: 

What is your question? The query you gave means "all results where B.refId=current row from A.ID".

Jonathan Feinberg
A: 

Can you just make your description.

A.*

Not sure if I understand the question though.

Nick Berardi
+1  A: 

Based on the question

SELECT B.description FROM
   A
   INNER JOIN
   B ON A.ID = B.refId
WHERE
   A.ID = 2

SELECT B.description FROM
   B
WHERE
   B.refid = 2

Otherwise, I don't think we understand the question...

gbn
Oh, as I said I cannot change those query. I don't know why my question is not clear for you. I just asking if is there a way to run query in context of single row instead of selecting all results.
DixonD