ä¸é¢ä»¥mysqlæ°æ®åºä¸ºä¾åæ
åµä¸ä¸è¯´æï¼
ä¸¤å¼ è¡¨ï¼insertTeståinsertTest2ï¼åè
ä¸ææµè¯æ°æ®ï¼
1.å¦æ2å¼ è¡¨çå段ä¸è´ï¼å¹¶ä¸å¸ææå
¥å
¨é¨æ°æ®ï¼å¯ä»¥ç¨è¿ç§æ¹æ³ï¼
INSERT INTO ç®æ 表 SELECT * FROM æ¥æºè¡¨;
insert into insertTest select * from insertTest2;
2.å¦æåªå¸æ导å
¥æå®å段ï¼å¯ä»¥ç¨è¿ç§æ¹æ³ï¼
INSERT INTO ç®æ 表 (å段1, å段2, ...) SELECT å段1, å段2, ... FROM æ¥æºè¡¨;
注æå段ç顺åºå¿
é¡»ä¸è´ã
insert into insertTest2(id) select id from insertTest2;
3.å¦ææ¨éè¦åªå¯¼å
¥ç®æ 表ä¸ä¸åå¨çè®°å½ï¼å¯ä»¥ä½¿ç¨è¿ç§æ¹æ³ï¼
INSERT INTO ç®æ 表
(å段1, å段2, ...)
SELECT å段1, å段2, ...
FROM æ¥æºè¡¨
WHERE not exists (select * from ç®æ 表
where ç®æ 表.æ¯è¾å段 = æ¥æºè¡¨.æ¯è¾å段);
1>.æå
¥å¤æ¡è®°å½ï¼
insert into insertTest2
(id,name)
select id,name
from insertTest
where not exists (select * from insertTest2
where insertTest2.id=insertTest.id);
2>.æå
¥ä¸æ¡è®°å½ï¼
insert into insertTest
(id, name)
SELECT 100, 'liudehua'
FROM dual
WHERE not exists (select * from insertTest
where insertTest.id = 100);
温馨提示:内容为网友见解,仅供参考