Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select * except 3 1

Status
Not open for further replies.

aalnaif

Technical User
Jan 12, 2007
44
CA
I want to select all columns from a table, EXCEPT three, which are called "id", "name", and "active".

I can't simply tell MySQL to select all the other columns, because I do not know beforehand how many columns there will be, or what they will be called.

Is there something like this that I can do?
> SELECT * EXCEPT id, name, active FROM table


 
To the best of my knowledge, you can't do that in a single query.

It is possible to issue a [tt]DESCRIBE tablename[/tt] query and use a programming language to process the return of that query to get all the columns and dynamically create the [tt]SELECT[/tt] query you need.



Want the best answers? Ask the best questions! TANSTAAFL!
 
I do not know beforehand how many columns there will be, or what they will be called"

what kind of an app are you building?

and if you don't know what columns the table has, how do you know that it will have exactly those three that you are trying to avoid?

r937.com | rudy.ca
 
It's just that I'm writing a stored procedure that is manipulating a table. And since I'm working on contract for this company, I want to make the stored procedure as modular as possible, so that if someone decides to add or drop a column from the table sometime in the future, he will not get a "column count does not match" syntax error when running my procedure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top