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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In Select statement? 3

Status
Not open for further replies.

StayAtHomeMom

Technical User
Sep 6, 2003
41
0
0
US
I’m confusing myself! All I’m trying to do is a Select Query from a large table with a matching field in another table. My large table is SalesDetail, and my other table is MexicanZips. There are too many Mexican Zips for me to place in the criteria row of my Select Query, so I put them in a separate table. I’m trying to select records from the SalesDetail table where the Zip field matches one of the zips in the MexicanZip table. I believe I need to use some kind of “In (SELECT …) statement in my query, but I’m messing the syntax up and I can’t find help in the Help Window.

Got any suggestions? THANK YOU!!
 



Please post your SQL.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Here is my SQL, even though I know it's wrong:

SELECT [SalesDetail].TerrNo AS [Terr No]
FROM [SalesDetail] INNER JOIN MexicanZips ON [SalesDetail].CustZIP = MexicanZips.BorderZip
WHERE ((([SalesDetail].CustZIP) In (SELECT [BorderZip] FROM [MexicanZips] As Tmp )))
GROUP BY [SalesDetail].TerrNo;
 



Code:
SELECT [SalesDetail].TerrNo AS [Terr No]

FROM  [SalesDetail] 
INNER JOIN MexicanZips 
   ON [SalesDetail].CustZIP = MexicanZips.BorderZip

GROUP BY [SalesDetail].TerrNo;

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 



Code:
SELECT [SalesDetail].TerrNo AS [Terr No]

FROM  [SalesDetail] 
INNER JOIN MexicanZips 
   ON [SalesDetail].CustZIP = MexicanZips.BorderZip

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
by doing the INNER JOIN you are effectively saying "bring me all the records from SalesDetail that have a CustZIP equal to MexicanZips.BorderZip":


all you need is:
Code:
SELECT [SalesDetail].TerrNo AS [Terr No]
FROM [SalesDetail] INNER JOIN MexicanZips ON [SalesDetail].CustZIP = MexicanZips.BorderZip

be sure to read the Understanding SQL Join link PHV posted above.

Leslie

Have you met Hardy Heron?
 
It worked!! Thank you for clearing the cobwebs!! And thank you PHV for the link about Joins. I will bookmark it for future reference.

You guys are THE BEST!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top