2015年1月7日 星期三

MYSQL SELECT完的資料放入INSERT INTO


正確與法

Insert Into prodclass (LarSeq,LarCode,MidSeq,MidCode) Select LarSeq,LarCode,max(MidSeq)+1,'12345' From prodclass Where LarSeq = (Select LarSeq From prodclass Where ClassId = 1)"

如果是以下這種語法會報錯

You have an error in your SQL syntax

Insert Into prodclass (LarSeq,LarCode,MidSeq,MidCode) Values((Select LarSeq From prodclass Where LarSeq = (Select LarSeq From prodclass Where ClassId = 1)),(Select LarCode From prodclass Where LarSeq = (Select LarSeq From prodclass Where ClassId = 1)),(Select max(MidSeq)+1 as newValue From prodclass Where LarSeq = (Select LarSeq From prodclass Where ClassId = 1)),1234)

INSERT INTO 中 如果採用 SELECT 則無法使用 VALUES

沒有留言:

張貼留言