How do I select column(s) by their "numeric" position in a table?

Posted by DulcimerDude on Stack Overflow See other posts from Stack Overflow or by DulcimerDude
Published on 2011-01-01T17:56:33Z Indexed on 2011/01/01 18:53 UTC
Read the original article Hit count: 163

Filed under:
|
|

I am trying to select columns by their "x" position in the table.

DBI

my $example = $hookup->prepare(qq{SELECT This,That,Condition,"I also want COLUMN-10" FROM tbl LIMIT ? ?});

    ###column_number=10 ordinal_position?? 
    $example->execute('2','10') or die "Did not execute";

Is this possible or do I need to run another single select to just that column?

One problem I encountered was with a col named "Condition". For some reason, when I tried to select Condition the execute would die. I never attempted but, What if the column name was SELECT?

Another note is the table is 75 cols wide and I only need 50 of them. The Col names are pretty verbose so, I would like to just call them by their "position". This would also allow the col names to be changed in the future without having to change the select statement.

I am quite the newbie so please explain any answers down to my level. Thanks for any assistance..

© Stack Overflow or respective owner

Related posts about mysql

Related posts about perl