query

  • Thread starter alxw3 via AccessMonster.com
  • Start date
A

alxw3 via AccessMonster.com

Need to join these 3 queries:
Query1:
B dp# T1
A 1 4
A 2 3
A 3 7
A 4 8

Query2:
B dp# T2
A 1 6
A 2 2

Query3:
B dp# T3
A 1 1

Output to look like:
B dp# T1 T2 T3
A 1 4 6 1
A 2 3 2
A 3 7
A 4 8
 
J

John Spencer

Combine them with a UNION Query (qUni_T)

SELECT B, [DP#] as DP, T1, "T1" as T
FROM [Query1]
UNION ALL
SELECT B, [DP#], T2, "T2" as T
FROM [Query2]
UNION ALL
SELECT B, [DP#], T3, "T3" as T
FROM [Query3]

Then use the union query as the basis of a crosstab query

TRANSFORM Sum(T)
SELECT B, DP
FROM qUni_T
GROUP BY B, DP
PIVOT T

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
A

alxw3 via AccessMonster.com

How about if ..
Query1:
B dp# T1 T2 T3
A 1 4 8 6
A 2 3 21 3
A 3 7 34 1
A 4 8 22 2

Query2:
B dp# G1 G3
A 1 6 2
A 2 2 6

Output to look like:
B dp# T1 T2 T3 G1 G3
A 1 4 8 6 6 2
A 2 3 21 3 2 6
A 3 7 34 1
A 4 8 22 2

John said:
Combine them with a UNION Query (qUni_T)

SELECT B, [DP#] as DP, T1, "T1" as T
FROM [Query1]
UNION ALL
SELECT B, [DP#], T2, "T2" as T
FROM [Query2]
UNION ALL
SELECT B, [DP#], T3, "T3" as T
FROM [Query3]

Then use the union query as the basis of a crosstab query

TRANSFORM Sum(T)
SELECT B, DP
FROM qUni_T
GROUP BY B, DP
PIVOT T

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
Need to join these 3 queries:
Query1:
[quoted text clipped - 19 lines]
A 3 7
A 4 8
 
J

John Spencer

How about you don't change your request?

You can still succeed and you will still need a union query.

SELECT B, [DP#], T1 as T, "T1" as ColName
FROM Query1
UNION ALL
SELECT B, [DP#], T2 as T, "T2" as ColName
FROM Query1
UNION ALL
SELECT B, [DP#], T3 as T, "T3" as ColName
FROM Query1
UNION ALL
SELECT B, [DP#], G1 as T, "G1" as ColName
FROM Query2
UNION ALL
SELECT B, [DP#], G3 as T, "G3" as ColName
FROM Query2

And then the same crosstab query as before.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================

How about if ..
Query1:
B dp# T1 T2 T3
A 1 4 8 6
A 2 3 21 3
A 3 7 34 1
A 4 8 22 2

Query2:
B dp# G1 G3
A 1 6 2
A 2 2 6

Output to look like:
B dp# T1 T2 T3 G1 G3
A 1 4 8 6 6 2
A 2 3 21 3 2 6
A 3 7 34 1
A 4 8 22 2

John said:
Combine them with a UNION Query (qUni_T)

SELECT B, [DP#] as DP, T1, "T1" as T
FROM [Query1]
UNION ALL
SELECT B, [DP#], T2, "T2" as T
FROM [Query2]
UNION ALL
SELECT B, [DP#], T3, "T3" as T
FROM [Query3]
Then use the union query as the basis of a crosstab query

TRANSFORM Sum(T)
SELECT B, DP
FROM qUni_T
GROUP BY B, DP
PIVOT T

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
Need to join these 3 queries:
Query1:
[quoted text clipped - 19 lines]
A 3 7
A 4 8
 
A

alxw3 via AccessMonster.com

tried to join the Query1-Query6. Got system resource exceeded error message.
access 2003.
have only one table, Table1.

Query1:
BD dp T T1
B 1 Ta 6
B 2 Tb 3
B 3 Tc 2
Query2:
BD dp T T2
B 1 Ta 7
B 2 Tb 1
B 3 Tc 8
Query3:
BD dp T T3
B 1 Ta 9
B 2 Tb 10
B 3 Tc 81
Query4:
BD dp T T4
B 1 Ta 11
B 2 Tb 6
B 3 Tc 5

Query5:
BD dp TV T5
B 1 Tr 4
B 2 Ts 7
Query6:
BD dp Tv T6
B 1 Tr 14
B 2 Ts 6
Query7:
BD dp Tv T7
B 1 Tr 14
B 2 Ts 5

Output:
BD dp T T1 T2 T3 T4 Tv T5 T6 T7
B 1 Ta 6 7 9 11 Tr 4 14 14
B 2 Tb 3 1 10 6 Ts 7 6 5
B 3 Tc 2 8 81 5


John said:
How about you don't change your request?

You can still succeed and you will still need a union query.

SELECT B, [DP#], T1 as T, "T1" as ColName
FROM Query1
UNION ALL
SELECT B, [DP#], T2 as T, "T2" as ColName
FROM Query1
UNION ALL
SELECT B, [DP#], T3 as T, "T3" as ColName
FROM Query1
UNION ALL
SELECT B, [DP#], G1 as T, "G1" as ColName
FROM Query2
UNION ALL
SELECT B, [DP#], G3 as T, "G3" as ColName
FROM Query2

And then the same crosstab query as before.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
How about if ..
Query1:
[quoted text clipped - 46 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top