View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] par_60056@hotmail.com is offline
external usenet poster
 
Posts: 42
Default !@#$ Query with Joins???

On Jun 21, 12:15 pm, Stephen
wrote:
Hi Folks,

I'm trying to create a query that might require a join of somekind but after
reading a number of web articles on joins I'm now more confused than ever...

I have two tables that contain the data I need. The First table has two
columns that relate to one column in my second table. I need to be able to
pull about four or five values from my second table, and one value from my
first table as it relates to the coresponding values from both. Since that
probably makes little to no sense...

SELECT DISTINCT Wearer.FrstName, Wearer.LastName, Garment.GarmDesc,
Wearer.Labl, Wearer.Aloc01, Wearer.ChrgQnty01
FROM Garment, Wearer
WHERE Wearer.GTypRcID01 = Garment.GTypRcID AND
Wearer.GTypRcID02 = Garment.GTypRcID AND
((LMWearer.OrdrRcID=269) AND (LMWearer.Nact=0))

but when I do it this way I get no results. when i go with either
Wearer.GTypRcID01 = Garment.GTypRcID
or
Wearer.GTypRcID02 = Garment.GTypRcID

I get pants or shirts related to the wearer but I need to retrieve both.

Please help before I split my head open from banging it against my keyboard :)

Thanks to All!!!


What you may want is an OR.

SELECT DISTINCT Wearer.FrstName, Wearer.LastName, Garment.GarmDesc,
Wearer.Labl, Wearer.Aloc01, Wearer.ChrgQnty01
FROM Garment, Wearer
WHERE (Wearer.GTypRcID01 = Garment.GTypRcID OR
Wearer.GTypRcID02 = Garment.GTypRcID) AND
((Wearer.OrdrRcID=269) AND (Wearer.Nact=0))

This could return 2 rows for each Wearer record.

If you only want 1 row for each wearer record, try joining to 2
instances of Garment.
You could do:

SELECT DISTINCT Wearer.FrstName, Wearer.LastName, GA.GarmDesc,,
GB.GarmDesc
Wearer.Labl, Wearer.Aloc01, Wearer.ChrgQnty01
FROM Garment GA, Garment GB, Wearer
WHERE Wearer.GTypRcID01 = GA.GTypRcID AND
Wearer.GTypRcID02 = GB.GTypRcID AND
((Wearer.OrdrRcID=269) AND (Wearer.Nact=0))

Pete