By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,486 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,486 IT Pros & Developers. It's quick & easy.

More Queries...

P: n/a
Hi All,

I have two tables, they contain:

Table1: ID1, Name1, Address1, Purchase1
Table2: ID2, Name2, Address2, Purchase2

I need a query which will show ID1, ID2, Name1, Address1 from Table1 and
Table2 which have the same name and address (Name1 = Name2 and Address1 =
Address2)

I also need a query which should add to Table1 all records from Table2, but
only for new Customers (Name2 and Address2 should not be present in the same
record in Table1)

Any help appreciated.

Regards,
Nicolae
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40******@duster.adelaide.on.net...
Hi All,

I have two tables, they contain:

Table1: ID1, Name1, Address1, Purchase1
Table2: ID2, Name2, Address2, Purchase2

I need a query which will show ID1, ID2, Name1, Address1 from Table1 and
Table2 which have the same name and address (Name1 = Name2 and Address1 =
Address2)
select t1.ID1, t2.ID2, t1.Name1, t1.Address1
from Table1 as t1 inner join Table2 as t2
on t1.Name1 = t2.Name2
and t1.Address1 = t2.Address2

I also need a query which should add to Table1 all records from Table2, but only for new Customers (Name2 and Address2 should not be present in the same record in Table1)


assuming ID is an automumber column:

insert into Table1(Name1, Address1, Purchase1)
select t2.Name2, t2.Address2, t2.Purchase2
from Table2 as t2
where not exists
(
select * from Table1 as t1
where t1.Name1 = t2.Name2
and t1.Address1 = t2.Address2
)
Nov 13 '05 #2

P: n/a
Thank you very much John, they work like a charm :-)


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.