这会拉回一行:
SELECT id FROM pin WHERE pinpicsid = '1'
我需要将该语句的结果放到这个X所在的位置:
INSERT INTO user_collection (pinid, username)
VALUES (X, 'ethanwa')
有没有办法将这两者结合起来?
答案 0 :(得分:4)
使用INSERT INTO SELECT -statement
INSERT INTO user_collection (pinid, username)
SELECT id, 'ethanwa' FROM pin WHERE pinpicsid = '1'
答案 1 :(得分:1)
INSERT INTO user_collection (pinid, username)
SELECT id, 'ethanwa'
FROM pin
WHERE pinpicsid = '1'