From: elsamiro2351 on 9 Mar 2010 06:59 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
From: elsamiro2351 on 9 Mar 2010 07:03 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 > 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 > >
|
Pages: 1 Prev: Nz - need code - Next: Comparison Query - How to write it! |