how can I join two querys --- to be precise

A

Ajith Nair

Hi,

I have a query called A which is

select id,custID from A1;

and second query B which is,

select id,CustId from A2;

I want to join this both query and get the result together.

B Regards
Ajith
 
A

Albert D. Kallal

Just open up the query builder, and jump to sql view.

Paste in your two quires with a "union all" command like

select id,custID from A1;

union all

select id,CustId from A2;

Ok, now save the query. The resulting query can be used for reports, or
even exporting
 
D

Douglas J. Steele

Sorry, Albert, but that won't work: you've included an unnecessary
semi-colon in the first subselect.

SELECT id, CustId FROM A1
UNION ALL
SELECT id, CustId FROM A2;

Note that if the same id occurs in both A1 and A2, it'll show up twice in
that query. If you only want it to show up once, use

SELECT id, CustId FROM A1
UNION
SELECT id,CustId FROM A2;

If the same id occurs in both, but different CustID values are associated
with them, they'll still both appear.

If you have a need to keep track of which table each record came from, use

SELECT id, CustId, "A1" AS Source FROM A1
UNION ALL
SELECT id, CustId, "A2" AS Source FROM A2;
 

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