PDA

View Full Version : Join two the columns of two tables



hunsnowboard
04-05-2009, 11:41 AM
Hi there Everyone! I have the following problem! I have two tables:
Table1
COUNTRY CITY
usa new york
uk london

and Table2:
NAME AGE
michael 32
linda 25

I would like to create a new table which displays the columns of both table1 and table two, so it should look like this:

Table3:
COUNTRY CITY NAME AGE
usa new york michael 32
uk london linda 25

I am very very new to acces, so please explain it to me very detailed! Thank you in advance!

f9073341
04-06-2009, 05:03 AM
You need to use a foreign key. For instance...

You could have an ID field in Table 1 as the primary key. In table 2 add a column which relates to that ID field. e.g.

Table 1
--------
1 USA NEW YORK
2 UK LONDON

Table 2
--------
1 Michael 32 1
2 Linda 25 1
3 John 42 2

Then use create an SQL statement...

SELECT Table2.Name, Table2.Age, Table1.Country, Table1.City
FROM Table1, Table2
WHERE Table2.CountryID = Table1.ID