开发者

Select columns by numbers - SELECT [m:n] FROM table_name

I have a database with many columns and sometimes I need to sele开发者_开发知识库ct quite a few.

Selecting all columns would be too much data. So lets say that:

DESC table_name

gives ordered column names, for example (A,B,C,D,E,F,G,H,I,J....). Is it possible that instead:

SELECT C,D,E,F FROM table_name;

I do something like this:

SELECT [3:6] FROM table_name

I know it makes no difference in this example, but I need to select over 40 columns with long names.


No, you can't SELECT [3:6] FROM table_name What do you think this is, some kind of modern computer language with sequences and ranges as first class data types? :-) :-). This is SQL.

You can, as a commenter pointed out, fetch the names of the columns in the table and then programmatically generate your SQL queries. This is, of course, something a bunch of different data-access-object packages do automatically.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜