【发布时间】:2012-06-18 10:07:53
【问题描述】:
我有 2 个表 Test1 和 Test1Update,结构如下
Test1
id name address
Test1Update
id name address
这里 Test1 是旧表,而 Test1Update 只是 Test1 表的副本 我想在这种情况下获取记录,
if(Test1.id=Test1Update.id){
select macthing values from Test1Update tables,and remaining unmatched values from Test1 table
}
else if(Test1.id!=Test1Update.id)
{
select * from Test1 only
}
举个例子
Test1 有类似的数据
Test1
id name address
1 john Ca
2 mary La
and Test1Update has data like
id name address
1 john Las Vega
s
现在我只想从 Test1Update 表中获取匹配的记录,并从
中获取所有不匹配的记录Test1 table so final output will be
id name address
1 john Las Vegas
2 mary La
这意味着只要有任何匹配项,就应该替换旧条目 使用 Test1Update 找到。
如何使用选择查询或过程来做到这一点?
告诉我一些方法。
【问题讨论】:
-
实际上你想选择 test1update 表的值,除非它们与 test1 表的值不同?
-
详细说明,update_table 是否包含表的所有行以及一些新行?
-
我试图用例子来阐述我的问题
-
是的,当且仅当它们与 test1 表的值不同时,我想选择 test1update 表的值,(简而言之,如果 test1 表中的任何值发生更改)
标签: mysql select stored-procedures if-statement