Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT (* - some_columns) FROM TABLE in SQL

Tags:

sql

select

I have a table with many columns among which I'd like to omit a few alone in my 'select' query. Something like select (* - columns_to_be_omitted) from myTable. Is there a way to do this, other than listing all the other columns in the query?

This is a one-time manual query, so I'm not that concerned about performance. Ease of use is the greater need here.

like image 598
Sundar R Avatar asked Sep 10 '26 02:09

Sundar R


1 Answers

You can't do this in straight SQL. The best you can do is write a stored procedure (anonymous or otherwise) that constructs a dynamic SQL statement and execute that.

You can include all or include some but you can't include all and exclude some (barring weird vendor extensions that may exist with different databases). There's no such thing in MySQL.

like image 91
cletus Avatar answered Sep 11 '26 19:09

cletus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!