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)
The answer posted by Mahomedalid has a small problem:
Inside replace function code was replacing "
<columns_to_delete>,
" by "", this replacement has a problem if the field to replace is the last one in the concat string due to the last one doesn't have the char comma "," and is not removed from the string.My proposal:
Replacing
<table>
,<database>
and `The column removed is replaced by the string "FIELD_REMOVED" in my case this works because I was trying to safe memory. (The field I was removing is a BLOB of around 1MB)
Would a View work better in this case?
In mysql definitions (manual) there is no such thing. But if you have a really big number of columns
col1
, ...,col100
, the following can be useful:Actually there is a way, you need to have permissions of course for doing this ...
Replacing
<table>, <database> and <columns_to_omit>
I agree that it isn't sufficient to
Select *
, if that one you don't need, as mentioned elsewhere, is a BLOB, you don't want to have that overhead creep in.I would create a view with the required data, then you can
Select *
in comfort --if the database software supports them. Else, put the huge data in another table.I wanted this too so I created a function instead.
So how it works is that you enter the table, then a column you don't want or as in an array: array("id","name","whatevercolumn")
So in select you could use it like this:
or