![](/img/trans.png)
[英]SQL INSERT INTO table(a, b , c) VALUES (:a, :b, :c, SELECT …)
[英]How to write a SQL patch that will take values from table A and insert as row within table B?
我只需要獲取photoProcess
表中具有storyId值(不是0或null)的每一行,並將條目插入到名為photoProcessStory
的新表中。
photoProcess
表中的行示例:
+----------------+----------+----------+
| processId | storyId | rating |
+----------------+----------+----------+
| 111111111 | 322 | 1 |
| 111111112 | 333 | 1 |
| 111111113 | 0 | 1 |
+----------------+----------+----------+
最終產生的photoProcessStory
表如下所示:
+-----+----------------+-------------------+
| id | processId | storyId |
+-----|----------------+-------------------+
| 1 | 111111111 | 322 |
| 2 | 111111112 | 333 |
+-----+----------------+-------------------+
任何幫助將不勝感激。 我有連接表並將值插入列的經驗,但是對於如何在這樣的補丁中插入行並不熟悉。
insert into photoProcessStory (processId, storyId)
select processId, storyId
from photoProcess
where storyId <> 0 and storyId is not null
您可以使用INSERT INTO.. SELECT
,例如:
INSERT INTO photoProcessStory (processId, storyId)
SELECT processId, storyId FROM photoProcess WHERE storyId <> 0;
這只是一個insert . . . select
insert . . . select
insert . . . select
?
insert into photoProcessStory(processId, storyId)
select processId, storyId
from photoProcess
where storyId <> 0;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.