Does INSERT INTO … SELECT … always match fields by ordinal position?

前端 未结 3 589
太阳男子
太阳男子 2021-02-18 16:16

My tests seem to confirm that

INSERT INTO a (x, y) SELECT y, x FROM b

maps b.y to a.x, i.e., the fields are matched o

3条回答
  •  悲&欢浪女
    2021-02-18 16:30

    Yes. It's because is not using ordinal position, it's just resolving the query by parts. First it Select from b, not taking into accounts columns names, since SQL don't resolve things using column names (you can make joins of different columns names). Then it will add the data to a, in the same way you specify the select in b. In fact, if you change the order, it will be inserted in other order ;)..

提交回复
热议问题