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 in this table (NOT MY DESIGN)
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 in this table (NOT MY DESIGN)
You can do:
without getting column3, though perhaps you were looking for a more general solution?
Based on @Mahomedalid answer, I have done some improvements to support "select all columns except some in mysql"
If you do have a lots of cols, use this sql to change group_concat_max_len
Agree on @Mahomedalid's answer. But I didn't wanted to do something like prepared statement and I didn't wanted to type all the fields. So What I had was a silly solution. Go to the table in phpmyadmin->sql->select, it dumps the query copy replace and done! :)
Just do
Then drop the column in you favourite programming language: php
I liked the answer from
@Mahomedalid
besides this fact informed in comment from@Bill Karwin
. The possible problem raised by@Jan Koritak
is true I faced that but I have found a trick for that and just want to share it here for anyone facing the issue.we can replace the REPLACE function with where clause in the sub-query of Prepared statement like this:
Using my table and column name
So, this is going to exclude only the field
id
but notcompany_id
Hope this will help anyone looking for a solution.
Regards
While I agree with Thomas' answer (+1 ;)), I'd like to add the caveat that I'll assume the column that you don't want contains hardly any data. If it contains enormous amounts of text, xml or binary blobs, then take the time to select each column individually. Your performance will suffer otherwise. Cheers!