Select all columns except one in MySQL?

后端 未结 30 2843
后悔当初
后悔当初 2020-11-22 00:46

I\'m trying to use a select statement to get all of the columns from a certain MySQL table except one. Is there a simple way to do this?

EDIT: There are 53 columns i

30条回答
  •  伪装坚强ぢ
    2020-11-22 01:32

    To the best of my knowledge, there isn't. You can do something like:

    SELECT col1, col2, col3, col4 FROM tbl
    

    and manually choose the columns you want. However, if you want a lot of columns, then you might just want to do a:

    SELECT * FROM tbl 
    

    and just ignore what you don't want.

    In your particular case, I would suggest:

    SELECT * FROM tbl
    

    unless you only want a few columns. If you only want four columns, then:

    SELECT col3, col6, col45, col 52 FROM tbl
    

    would be fine, but if you want 50 columns, then any code that makes the query would become (too?) difficult to read.

提交回复
热议问题