我想为下面的场景编写一个Mysql查询。
1.检查表(例如: tableA)是否存在。
2.检查表中是否有数据。
3.如果存在tableA且表中有数据,则将所有数据移动到另一个表(例如: tableB) ( db中有tableB,两个表具有相同的结构)
4.降低tableA
是否可以编写避免mysql存储过程的mysql查询?
发布于 2014-03-19 14:07:41
我能够用下面的查询做前三次,但是drop表是不可能的。希望能帮上忙!
有两个表:table_1(旧的),table_2(新的)。两者都有一个列"ID“。
insert into table_2(id) #inserts into table
select case when
(
select count(*) from table_1 a #checks if there are any records in the table
where exists #checks if table exists
(select 1 from table_1 b where a.id=b.id))>0 then
id
else 0 end
from table_1https://stackoverflow.com/questions/22507188
复制相似问题