mysql 列 6位数字,MySQL:如何按数字选择列?

I'm writing a program, and I have the need to SELECT column names by number, rather than by name.

That is, say the attributes to my table are:

SSN, FirstName, LastName, MiddleName, Address, City, State, Zip

How could I select the data just from columns 0 (SSN), 1 (FirstName), 2(LastName), 6 (State)

Is there a way to do this without delving into information schema?

解决方案

You should reconsider your design. A table can be changed, it can evolve, column order is very fickle. You should NOT hardcode column numbers.

ADDENDUM

By "evolve" and "fickle", I don't mean that the database engine can move them around. That's pretty much fix. No, I mean that needs can change in the future and the table design can be updated. It will be easier in the future to adapt your old code if you list the actual column names rather than the column position order. Think of column position just like row position: don't expect a particular order in the result based on input order, but rather make your query give you the order you need.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值