2017-04-25 39 views
-1

我有兩個表。 customer1表和顧客2無法執行條件插入int配置單元

customer1表

ID名稱 1插孔 2約翰 3瓊斯

客戶2

ID名稱

客戶2表是空的。現在,我必須檢查客戶2中是否存在特定名稱'傑克',如果客戶2中不存在名稱'傑克',則插入。

+0

你能提供這個問題的代碼,你試圖自己解決你的問題嗎?沒有代碼,真的很難找到你想要達到的目標。 – Felix

+0

另請參閱此答案:http://stackoverflow.com/a/37744071/2700344 – leftjoin

+0

我使用的查詢是:插入到表customer1 select * from customers where customers.name not in(select customer1 from name); – aswinkarthikeyan

回答

0

下面的查詢應該服務器的目的。我假設ID是鏈接表之間的關鍵,如果不是,您可以在連接條件中使用該名稱。

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