我有一個選擇查詢,我正在使用它來挑選我的數據庫中一段時間內沒有提及的聯繫人。我想運行一個INSERT查詢來爲所有使用此select查詢返回的記錄輸入一個重複註釋...問題是我不確定如何去做。mySQL - 與此SELECT查詢匹配相同記錄的INSERT查詢?
SELECT查詢本身可能有點混亂。我基本上希望有選擇的,從每一個合作伙伴最近的音符,然後選擇尚未從某個日期有了一個音符和背部唯一合作伙伴... SELECT查詢雲:
SELECT * FROM
(
SELECT * FROM
(
SELECT
partners.partners_id,
partners.CompanyName,
notes.Note,
notes.DateCreated
FROM
notes
JOIN
partners ON notes.partners_id = partners.partners_id
ORDER BY notes.DateCreated DESC
) AS Part1
GROUP BY partners_id
ORDER BY DateCreated ASC
) AS Part2
WHERE
DateCreated <= '2013-01-15'
將如何運行一個INSERT查詢只會進入與此SELECT相同的記錄中?如果你想要做的這一切都在SQL
INSERT INTO notes
(
notes_id,
partners_id,
Note,
CreatedBy,
DateCreated
)
SELECT
UUID(),
partners.partners_id,
'Duplicated message!',
'User',
'2013-02-14'
FROM
partners
你的意思是更新查詢嗎? – 2013-02-14 22:21:03
INSERT INTO table_name(column1,column2,...)SELECT(value1,value2,...).... – Slowcoder 2013-02-14 22:23:41