Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a query off the results of another

Status
Not open for further replies.

jondel81

Technical User
Jul 27, 2003
71
US
TheQuery:
SELECT DISTINCT ItemFile.GroupID, ITEM.NBR
FROM ITEM, ItemFile
WHERE (((ITEM.NBR) Between [ItemFile].[Range_Low] And [ItemFile].[Range_High]));
UNION SELECT Group_Items.GroupID, Group_Items.NBR
FROM Group_Items;

Second Query:
SELECT TheQuery.GroupID, GroupItems.NBR
FROM TheQuery RIGHT JOIN TheQuery AS GroupItems ON TheQuery.GroupID = GroupItems.GroupID
WHERE (((TheQuery.NBR)="4874095M"));

You see how the second query calls on “TheQuery”. How do I make these two queries one query?


------
 
Check out derived tables in Books Online. The critical thing with a derived table is you must give it an alias. Exaxmple:
Code:
select a.itemno, field1 from table1 join (select idfield, itemno from table2 where date= '10/1/2004') a
on table1.idfield = a.idfield

Questions about posting. See faq183-874
 
Cookbook guide: insert (first query) between "FROM" and "TheQuery". :)
 
You notice it does call "TheQuery" twice. Do I need to put the "TheQuery" in twice? If so were?

Something like this? I could not get it to work.

SELECT TheQuery.GroupID, GroupItems.NBR
FROM (here) TheQuery RIGHT JOIN (here) AS GroupItems ON TheQuery.GroupID = GroupItems.GroupID
WHERE (((TheQuery.NBR)="4874095M"));

------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top