Re: conditional join?
- From: "Chris2" <rainofsteel.NOTVALID@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Jun 2007 16:38:08 -0700
"Bart" <Bart@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8DCDDF8B-1F08-477A-8782-0A9FAD40663C@xxxxxxxxxxxxxxxx
Hi Chris,
I believe I did try what you suggest below and indeed got the result that
you suggest below which is indiscriminate in regard to whether a match was
possible at a deeper level. I am assuming I need to put in some conditional
coding but I don't know where I can do that.
Paul
Paul,
I am unable to determine what it is you wish to do.
Are you trying to distinguish between what records were found with 4-column matching,
3-column matching, 2-column matching, and 1-column matching?
If so, you could run a UNION with four SELECT statements, with an additional column to
distinguish the groups, like so:
Query:
SELECT 1 As MatchingGroups
,T2.Index1
,T2.Index2
,T2.Index3
,T2.Index4
FROM TableA AS T1
INNER JOIN
TableB AS T2
ON (T1.Index1 = T2.Index1
AND T1.Index2 = T2.Index2
AND T1.Index3 = T2.Index3
AND T1.Index4 = T2.Index4)
UNION ALL
SELECT 2 As MatchingGroups
,T2.Index1
,T2.Index2
,T2.Index3
,T2.Index4
FROM TableA AS T1
INNER JOIN
TableB AS T2
ON (T1.Index1 = T2.Index1
AND T1.Index2 = T2.Index2
AND T1.Index3 = T2.Index3)
UNION ALL
SELECT 3 As MatchingGroups
,T2.Index1
,T2.Index2
,T2.Index3
,T2.Index4
FROM TableA AS T1
INNER JOIN
TableB AS T2
ON (T1.Index1 = T2.Index1
AND T1.Index2 = T2.Index2)
UNION ALL
SELECT 4 As MatchingGroups
,T2.Index1
,T2.Index2
,T2.Index3
,T2.Index4
FROM TableA AS T1
INNER JOIN
TableB AS T2
ON (T1.Index1 = T2.Index1)
Comments:
I tried entering some test data into the tables I created, and discovered something that
makes me feel certain I did not guess structure correctly.
With the way the rules are set up, all four columns appear to have to have the same
values, rendering columns 2, 3, and 4 irrelevant (which can't be right, I think).
Can you please post your table structures (including all indexes and relationships),
sample data, desired results, and any SQL attempted to date (including why it didn't
work).
Sincerely,
Chris O.
.
- Follow-Ups:
- Re: conditional join?
- From: Bart
- Re: conditional join?
- References:
- Re: conditional join?
- From: Chris2
- Re: conditional join?
- From: Bart
- Re: conditional join?
- Prev by Date: Re: Query by form with 3 parameters
- Next by Date: Re: Create an Error Message
- Previous by thread: Re: conditional join?
- Next by thread: Re: conditional join?
- Index(es):
Relevant Pages
|