A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Subquery



 
 
Thread Tools Display Modes
  #1  
Old February 5th, 2010, 08:50 PM posted to microsoft.public.access.queries
hoachen
external usenet poster
 
Posts: 97
Default Subquery

I am trying to compare two fields data if there are match.

Table 1:
item#
123

Table 2:
Item# ItemName Edition creator
123 Name1 05 Smith
456 EkName2 05 Smith
111 Name1 11th 10 Larry
656 EkName4 latest John

The result should return below, because the Edition and the creator match
even though the ItemName and the item# does not match.
123 Name1 05 Smith
456 EkName2 05 Smith

I tried SELECT ItemName, Edition (select temp.ItemName, Edition, from
[ItemTable] AS temp Where ItemName like "ek*") from [ItemTable] Order Edition
  #2  
Old February 5th, 2010, 09:47 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Subquery

Two query method:
First query saved as TheSavedQuery
SELECT Edition, Creator
FROM ItemTable INNER JOIN [Table1]
ON ItemTable.[Item#] = [Table1].[Item#]

Second query uses the ItemTable table and the saved query.
SELECT ItemTable.*
FROM ItemTable INNER JOIN TheSavedQuery
ON ItemTable.Edition = TheSavedQuery.Edition
AND ItemTable.Creator = TheSavedQuery.Creator



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

hoachen wrote:
I am trying to compare two fields data if there are match.

Table 1:
item#
123

Table 2:
Item# ItemName Edition creator
123 Name1 05 Smith
456 EkName2 05 Smith
111 Name1 11th 10 Larry
656 EkName4 latest John

The result should return below, because the Edition and the creator match
even though the ItemName and the item# does not match.
123 Name1 05 Smith
456 EkName2 05 Smith

I tried SELECT ItemName, Edition (select temp.ItemName, Edition, from
[ItemTable] AS temp Where ItemName like "ek*") from [ItemTable] Order Edition

  #3  
Old February 5th, 2010, 10:11 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Subquery

Try these two queries --
qryPullMatch --
SELECT [Item#], ItemName, Edition, Creator, (select temp.[Item#]
FROM [ItemTable] AS temp Where temp.Edition = [ItemTable].Edition AND
[ItemTable].Creator = temp.Creator) AS temp1
FROM [ItemTable]
ORDER BY Edition, Creator;

SELECT [Item#], ItemName, Edition, Creator
FROM [ItemTable]
ORDER BY Edition, Creator
UNION ALL SELECT [Item#], ItemName, Edition, Creator
FROM [ItemTable] INNER JOIN qryPullMatch ON [ItemTable].[Item#] =
qryPullMatch.temp1
ORDER BY Edition, Creator;

--
Build a little, test a little.


"hoachen" wrote:

I am trying to compare two fields data if there are match.

Table 1:
item#
123

Table 2:
Item# ItemName Edition creator
123 Name1 05 Smith
456 EkName2 05 Smith
111 Name1 11th 10 Larry
656 EkName4 latest John

The result should return below, because the Edition and the creator match
even though the ItemName and the item# does not match.
123 Name1 05 Smith
456 EkName2 05 Smith

I tried SELECT ItemName, Edition (select temp.ItemName, Edition, from
[ItemTable] AS temp Where ItemName like "ek*") from [ItemTable] Order Edition

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:30 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.