union query

J

jean.ulrich

Hi

I have 2 queries Q1 and Q2

Each query have the same number of fields and the same names of field

Q1 contain "NoEmp" , "Sanction1", "Motif1", "Motif11", "NoDécision1",
"Date1" and contains 336 records
Q2 contain "NoEmp" , "Sanction1", "Motif1", "Motif11", "NoDécision1",
"Date1" and contains 57 records

How should I proceed to obtain a query containing both Q1 and Q2 with
393 records ?

I have try union query but I guess I am wrong with the syntax in SQL

thanks
 
P

Peter Jamieson

I have try union query but I guess I am wrong with the syntax in SQL

UNION isn't enough, because it eliminates duplicate rows, so if the same row
appears in both Q1 and Q2 you will only get 392 records. As long as every
row in Q1 is different and every row in Q2 is different, try something like

SELECT 1, * FROM Q1
UNION
SELECT 2, * FROM Q2

or

SELECT 1 AS 'x', * FROM Q1
UNION
SELECT 2 AS 'x', * FROM Q2

then use another query to select all the columns except 'x' from your new
query.

Peter Jamieson
Hi

I have 2 queries Q1 and Q2

Each query have the same number of fields and the same names of field

Q1 contain "NoEmp" , "Sanction1", "Motif1", "Motif11", "NoDécision1",
"Date1" and contains 336 records
Q2 contain "NoEmp" , "Sanction1", "Motif1", "Motif11", "NoDécision1",
"Date1" and contains 57 records

How should I proceed to obtain a query containing both Q1 and Q2 with
393 records ?

I have try union query but I guess I am wrong with the syntax in SQL

thanks
 
R

Roger Carlson

Use UNION ALL in your Union query. The plain UNION statement will remove
duplicates, however UNION ALL will show duplicated records.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

Hi

I have 2 queries Q1 and Q2

Each query have the same number of fields and the same names of field

Q1 contain "NoEmp" , "Sanction1", "Motif1", "Motif11", "NoDécision1",
"Date1" and contains 336 records
Q2 contain "NoEmp" , "Sanction1", "Motif1", "Motif11", "NoDécision1",
"Date1" and contains 57 records

How should I proceed to obtain a query containing both Q1 and Q2 with
393 records ?

I have try union query but I guess I am wrong with the syntax in SQL

thanks
 

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