recursively retrieve records from 2nd table based on records from

E

elsamiro2351

I have two separate queries, that show the wanted results.
I tried hard but i cannot "merge" them into query/subquery.
I am not sure if subqueries are the right way to solve this.


I keep having errors or results that aren't the ones expected.
Below is the query , with simplified table/field names.

SELECT tbl1.ID FROM tbl1
(SELECT ID, field2 FROM tbl2 WHERE field2 = tbl1.ID )
ORDER BY tbl1.ID DESC;

Using words the query should

Display table1.ID ASCENDING
for each
table1.ID lookup table2.ID WHERE table2.field2 = table1.ID

What I am looking for to be displayed:

tbl1.ID tbl2.ID tbl2.field2
1 99
99 1
123 1
567 1
2 766
2 456
766 2
456 2
999 2
 
E

elsamiro2351

What I am looking for to be displayed:

tbl1.ID tbl2.ID tbl2.field2
1 99
99 1
123 1
567 1
2 766
2 456
766 2
456 2
999 2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top