sample table:
idtbl color
1 red
2 green1
3 yellow1
4 blu
5 blu
6 green2
7 yellow2
8 red
9 blu
10 green3
11 yellow3
...
query:
IDqry V G
1 green1 yellow1
2 green2 yellow2
3 green3 yellow3
...
green1 idtbl+1 = yellow1 idtbl, ...
Perhaps this explains better
I'm still not 100% sure but I _think_ what is required is the order
relative to idtbl of the occurrence (qryID) of yellow and green
respectively.
With Jet lacking the FULL OUTER JOIN syntax (the UNION workaround with
the derived tables including subqueries would look horrid!), I opt to
use a Sequence table (the standard trick of having a table of
incrementing integers). You may have to change the % wildcard character
SELECT [Sequence].i AS IDqry,
Greens.color AS V, Yellows.color AS G
FROM (
[Sequence] LEFT OUTER JOIN (
SELECT T1.idtbl, T1.color, (
SELECT COUNT(*)
FROM Marco
WHERE color LIKE 'green%' AND T1.idtbl >= idtbl
) AS occurance_nbr
FROM Marco AS T1
WHERE T1.color LIKE 'green%'
) AS Greens ON [Sequence].i = Greens.occurance_nbr
) LEFT OUTER JOIN (
SELECT T1.idtbl, T1.color, (
SELECT COUNT(*)
FROM Marco
WHERE color LIKE 'yellow%' AND T1.idtbl >= idtbl
) AS occurance_nbr
FROM Marco AS T1
WHERE T1.color LIKE 'yellow%'
) AS Yellows ON [Sequence].i = Yellows.occurance_nbr
WHERE Greens.color IS NOT NULL
AND Yellows.color IS NOT NULL