To make a query from two independent tables

  • Thread starter Thread starter Lilian
  • Start date Start date
L

Lilian

Hi,
Is it possible to make a query for two independent not related with each
other tables? For example both tables contain info idnummer, projektname,
date.
Best regards,
Lilian
 
Sure. It's called a union query and the SQL looks something like this:

SELECT idnummer, projektname, [date]
FROM Table1
UNION ALL
SELECT idnummer, projektname, [date]
FROM Table2 ;

A few things to remember.

1. There is a difference between UNION ALL and just UNION. UNION ALL returns
all records including duplicates. UNION ALL is also faster if you have a
large number of records. If you just want unique records, just UNION.

2. The number and (usually) data types of the fields need to be the same.
There are some tricks to get around this problem, but for the most part, this
is true.
 

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

Back
Top