-1

I have two tables . Customer1 and Customer2

Customer1

id name 1 jack 2 john 3 jones

Customer 2

id name

The Customer 2 table is empty . Now i have to check if a particular name say 'jack' is present or not in customer 2 and to insert if a name 'jack' is not present in customer 2 .

1 Answers1

0

The below query should server the purpose. I am assuming that ID is the key to link between the tables, if not you can use the name in the join condition.

  `insert into customer2 
select customer1.* 
from customer1 
left join customer2 
on (customer1.id=customer2.id) 
where customer1.name='jack' and isnull(customer2.id);`
Abraham
  • 423
  • 3
  • 9