如何将表1字段中的数据插入表2字段

时间:2017-04-04 04:47:49

标签: mysql sql database

            strSQL = "INSERT INTO MEMBER (" & _
                        "MERCHANT_UID, MEMBER_ID, ACCOUNT_ID, LOGIN_PWD, SALUTATION, FULL_NAME, " & _
                        "IC_NO, DOB, GENDER, NATIONALITY, CITY, STATE, " & _
                        "COUNTRY, POSTCODE, PHONE_MOBILE, PHONE_HOUSE, PHONE_OFFICE, EMAIL, SOURCE, IS_REQ_CHG_PWD, " & _
                        "ADDRESS_1, ADDRESS_2, ADDRESS_3, " & _
                        "CREATED_BY, CREATED_DATETIME, " & _
                        "MODIFIED_BY, MODIFIED_DATETIME) " & _
                     "VALUES (" & _
                        "@MERCHANT_UID, @MEMBER_ID, @ACCOUNT_ID, @LOGIN_PWD, @SALUTATION, @FULL_NAME, " & _
                        "@IC_NO, @DOB, @GENDER, @NATIONALITY, @CITY, @STATE, " & _
                        "@COUNTRY, @POSTCODE, @PHONE_MOBILE, @PHONE_HOUSE, @PHONE_OFFICE, @EMAIL, @SOURCE, @IS_REQ_CHG_PWD, " & _
                        "@ADDRESS_1, @ADDRESS_2, @ADDRESS_3, " & _
                        "@CREATED_BY, @CREATED_DATETIME, " & _
                        "@MODIFIED_BY, @MODIFIED_DATETIME);"

以上是表1,它是成员表。表2将是member_activation表

中的Account_ID_Format(字段名称)
  • 我想将上述查询中的account_ID_Format插入表2.我该怎么做?

2 个答案:

答案 0 :(得分:1)

你可以这样使用insert select语句

INSERT INTO tablename (columnname1,columnname2,..) SELECT columnname1,columnname2,.. FROM tablename2 WHERE id = 4 

这将完成工作

INSERT INTO members (account_ID_Format) SELECT account_ID_Format FROM members_activation WHERE id = 4 

答案 1 :(得分:0)

INSERT INTO member_activation
SELECT account_ID_Format
FROM member
WHERE <condition>

OR

Select account_ID_Format
into
member_activation
from member
where <condition>