mysql防止插入行自动排序
我使用Codeigniter执行插入到mysql(不确定是否相关),插入后我有表列和一些类似这样的数据:
[invoice_id][product_id][unit_cost][quantity] [42][1][50][2] [42][2][100][3] [42][5][45][1]
问题是mysql首先按invoice_id然后按product_id自动排序,如上所述。
在插入它们之前,我的发票项目列表位置是:
[42][5][45][1] [42][1][50][2] [42][2][100][3]
我不想要任何这种自动排序,因为当我检索它们时,它们就像数据库中的列表而不是发票中的列表。我认为我不能对特定列使用排序,因为它们首先都是随机的。
我只能开始考虑添加另一列 [position] 包含数字只是为了稍后对其进行排序,或者是否有更好的方法没有它?
预先感谢您的回复。
I use Codeigniter to perform insert to mysql (not sure if relevant), I have table column and some data like this after I insert:
[invoice_id][product_id][unit_cost][quantity] [42][1][50][2] [42][2][100][3] [42][5][45][1]
The problem is mysql auto sort it by invoice_id first then product_id like the above.
Before I insert them, my invoice item-list position was :
[42][5][45][1] [42][1][50][2] [42][2][100][3]
I do not want any of this auto-sort because when I retrieve them, they went like the list in database not as in the invoice. I dont think I can use sort for a particular column because they are all random in the first place.
I can only start thinking to add another column [position] contain number just for the sake of sorting it later, or is there a better way without it?
Thanks in advance for any reply.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您指定
ORDER BY
子句,否则无法保证 MySql 结果集的顺序。如果无法使用已有的参数进行排序,唯一的方法就是向表中添加另一列。通常,这将是一个自动增量整数字段。然后,您可以按 id 排序,并按照输入的顺序返回行。You are not guaranteed the order of MySql resultsets unless you specify an
ORDER BY
clause. The only way to do it if you cannot sort with the parameters you already have would be to add another column to the table. Typically this would be an autoincrement integer field. You would then be able to order by id, and return the rows in the order they were entered.