hi to all
I have SQL that counts, for each of a large number of trials, matches between columns X and Y of tbl_XY.
In the table shown below, when TRIAL = 1, the SQL output correctly shows that there are 2 matches (X=Y=23 and X=Y=31).
The SQL works perfectly for the vast majority of my Trials, but it fails when there are REPEATS in either the X or the Y column. For example, in Trial 276 the SQL indicates that there are 2 matches (X=Y=44 and X=Y=44). But, I want there to be only 1 match indicated here. After the 1st X=44 matches Y=44, these values need to be removed from further consideration. The 2nd X=44 should find no match in the Y column.
Using the same reasoning, I want Trial 3544 to indicate 5 matches, not 12.
I'd be grateful for any hints pointing me in the right direction. Vicky C.
I have SQL that counts, for each of a large number of trials, matches between columns X and Y of tbl_XY.
Code:
[b]
qry_XY [/b]
SELECT T1.Trial, COUNT(*) AS MatchCount
FROM tbl_XY AS T1 INNER JOIN tbl_XY AS T2 ON (T1.Trial=T2.Trial) AND (T1.X=T2.Y)
GROUP BY T1.Trial;
In the table shown below, when TRIAL = 1, the SQL output correctly shows that there are 2 matches (X=Y=23 and X=Y=31).
The SQL works perfectly for the vast majority of my Trials, but it fails when there are REPEATS in either the X or the Y column. For example, in Trial 276 the SQL indicates that there are 2 matches (X=Y=44 and X=Y=44). But, I want there to be only 1 match indicated here. After the 1st X=44 matches Y=44, these values need to be removed from further consideration. The 2nd X=44 should find no match in the Y column.
Using the same reasoning, I want Trial 3544 to indicate 5 matches, not 12.
Code:
[b]
tbl_XY qry_XY (ACTUAL output) qry_XY (DESIRED output)
Trial Part X Y Trial MatchCount Trial MatchCountbb[/b]
1 1 23 57 1 2 1 2
1 2 99 6 276 2 276 1
1 3 18 47 3544 12 3544 5
1 4 31 8
1 5 88 31
1 6 66 23
276 1 44 16
276 2 44 97
276 3 35 3
276 4 7 88
276 5 46 44
276 6 79 19
3544 1 41 24
3544 2 13 13
3544 3 41 24
3544 4 24 41
3544 5 24 41
3544 6 13 41
I'd be grateful for any hints pointing me in the right direction. Vicky C.