合并到广告订单中 [英] MERGE INTO insertion order

查看:81
本文介绍了合并到广告订单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的声明:

I have a statement that looks something like this:

MERGE INTO someTable st
USING
(
    SELECT id,field1,field2,etc FROM otherTable
) ot on st.field1=ot.field1
WHEN NOT MATCHED THEN
    INSERT (field1,field2,etc)
    VALUES (ot.field1,ot.field2,ot.etc)

其中 otherTable 具有一个自动递增的 id 字段.

where otherTable has an autoincrementing id field.

我希望插入 someTable 的顺序与 otherTable id 字段的顺序相同,以使插入不匹配字段时,会保留 id 的顺序.

I would like the insertion into someTable to be in the same order as the id field of otherTable, such that the order of ids is preserved when the non-matching fields are inserted.

快速浏览文档可能表明存在没有支持此功能的功能.

A quick look at the docs would appear to suggest that there is no feature to support this.

这是否可行,或者还有其他方式可以满足我的要求吗?

Is this possible, or is there another way to do the insertion that would fulfil my requirements?

一种方法是将一个附加字段添加到 someTable 中,以捕获顺序.如果可能的话,我宁愿不这样做.

One approach to this would be to add an additional field to someTable that captures the ordering. I'd rather not do this if possible.

...经过思考,上述方法似乎是可行的方法.

... upon reflection the approach above seems like the way to go.

推荐答案

您为什么要关心ID匹配的顺序?这将对您查询数据有何不同?相关表应通过主键和外键连接,而不要插入订单记录.在数据库中,表并不是固有地以特定方式排序的.订单应来自order by子句.

Why would you care about the order of the ids matching? What difference would that make to how you query the data? Related tables should be connected through primary and foreign keys, not order records were inserted. Tables are not inherently ordered a particular way in databases. Order should come from the order by clause.

有关为什么要执行此操作的更多说明可以帮助我们引导您找到合适的解决方案.

More explanation as to why you want to do this might help us steer you to an appropriate solution.

这篇关于合并到广告订单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆