我需要以下SQL的帮助
我有两个表titles
和postcode_db
我想左联接和插入到第三个表
SELECT titles.id, titles.title, titles.address,
postcode_db.postcode, postcode_db.suburb
FROM titles
LEFT JOIN postcode_db ON titles.address = postcode_db.suburb;
以上作品。我想插入
titles_postcode
titles.id AS titles_postcode.title_id
titles.title AS titles_postcode.title
postcode_db.postcode
INSERT INTO titles_postcode
(titles.id AS titles_postcode.title_id,
titles.title AS titles_postcode.title,
postcode_db.postcode AS titles_postcode.postcode)
SELECT titles.id, titles.title, titles.address,
postcode_db.postcode, postcode_db.suburb
FROM titles
LEFT JOIN postcode_db ON titles.address = postcode_db.suburb;
其返回的
error right syntax to use near 'AS titles_postcode.title_id, titles.title AS titles_postcode.title, postcode_db.' at line 1
最佳答案
尝试这个:
INSERT INTO titles_postcode (title_id, title, postcode)
SELECT titles.id, titles.title, postcode_db.postcode
FROM titles
LEFT JOIN postcode_db ON titles.address = postcode_db.suburb;
关于mysql - 插入左联接SQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21985219/