-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 .

  • can you provide code for this question which you tried to fix your problem by yourself? without code it's really hard to find out what you want to achieve. – Felix Apr 25 '17 at 12:04
  • See also this answer: http://stackoverflow.com/a/37744071/2700344 – leftjoin Apr 25 '17 at 12:09
  • the query i used is : insert into table customer1 select * from customers where customers.name not in (select name from customer1); – aswinkarthikeyan Apr 25 '17 at 12:27

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