I have 3 queries with different field name. Each query has 1 field name. Need to combine those 3 into 1 query.
From
Query1: Field1
Query2: Field2
Query3: Field3
To FinalQuery: Field1|Field2|Field3
Thanks in advance.
Jv
I tried to append query but no luck, records were duplicate producing lots of data. Just need to straight combine those3 query.
CodePudding user response:
To solve this task well, @Gustav suggestion is powerfull method.
Simple, at hand method to add rownumber to query, for example:
Create Query in Access Q1n (in Query constructor - only SQL mode)
SELECT query1.field1,count(*) as cn
FROM query1 INNER JOIN query1 AS query1_1 ON query1.field1 >= query1_1.field1
group by query1.field1
and queries Q2n,Q3n in the same way
SELECT query2.field2,count(*) as cn
FROM query2 INNER JOIN query2 AS query2_1 ON query2.field2 >= query2_1.field2
group by query2.field2
SELECT query2.field2,count(*) as cn
FROM query2 INNER JOIN query2 AS query2_1 ON query2.field2 >= query2_1.field2
group by query2.field2
Result query
SELECT *
FROM (q1n LEFT JOIN q2n ON q1n.cn = q2n.cn) LEFT JOIN q3n ON q2n.cn = q3n.cn;
field1 | q1n.cn | field2 | q2n.cn | field3 | q3n.cn |
---|---|---|---|---|---|
q1-1 | 1 | q2-1 | 1 | q3-1 | 1 |
q1-2 | 2 | q2-2 | 2 | q3-2 | 2 |
q1-3 | 3 | q2-3 | 3 | q3-3 | 3 |
q1-4 | 4 | q2-4 | 4 | ||
q1-5 | 5 |