开发者

query insert and select explaination

I am confused about this query where it uses insert statement and then ignore and then select. Can someone explain me this? Thanks

INSERT IGNORE INTO
        myTable
    SELECT
        $var1  AS `CMMNCTID`,
        $var2  AS `ENCID`,
        variableID,
        ProductID,
        Cu开发者_运维知识库stomerID,
        Age,
        "" AS `myJ`,
        "" AS `myI`
    FROM
        table2
    JOIN
        table3
    ON
        table2.ID= table3.ID


INSERT IGNORE in a keyword mysql: If the insert will cause a Primary key or Unique key error, it should skip that row.

INSERT ... SELECT: is used to copy data from another table.

http://dev.mysql.com/doc/refman/5.1/en/insert.html


The SELECT is a subquery. What the INSERT is doing is inserting whatever is contained in the join of table2 and table3, into myTable. The IGNORE tells it to ignore any entries for keys that already exist in myTable and to just insert whatever doesn't yet exist.

It seems the purpose of the query is to combine the data that is associated between table2 and table3 and dump it into myTable.


It takes results from the SELECT query on tables table2 and table3 and inserts the results into table myTable. IGNORE keyword simply tells mysql to ignore any errors that occur while executing the INSERT query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜