Select all columns except one in MySQL?

后端 未结 30 2866
后悔当初
后悔当初 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:30

    My main problem is the many columns I get when joining tables. While this is not the answer to your question (how to select all but certain columns from one table), I think it is worth mentioning that you can specify table. to get all columns from a particular table, instead of just specifying .

    Here is an example of how this could be very useful:

    select users.*, phone.meta_value as phone, zipcode.meta_value as zipcode
    
    from users
    
    left join user_meta as phone
    on ( (users.user_id = phone.user_id) AND (phone.meta_key = 'phone') )
    
    left join user_meta as zipcode
    on ( (users.user_id = zipcode.user_id) AND (zipcode.meta_key = 'zipcode') )
    
    

    The result is all the columns from the users table, and two additional columns which were joined from the meta table.

提交回复
热议问题