SQL query to select all columns in a table except two columns

I have a table in ms-access with column names from A to H

TableA ABCDEFGH 

how can I write a query to select all columns except columns B and F. The result of the query should be

 ACDEGH 

Do we have something like this

 select * from TableA except B, F ? 
+4
source share
7 answers

No, you are stuck with

 select a, c, d, e, g, h from TableA 
+2
source

No no. You have to use

 SELECT A, C, D, E, G, H FROM TableA 

And it’s good if you ask me. SELECT * quite vicious.

+3
source
 select A, C, D, E, G, H from TableA 
+1
source

I don’t know for sure, but it is definitely better to explicitly specify the columns you want to select. This makes any potential changes to your table more liveable as you can use aliases, etc.

+1
source
 select A, C, D, E, G, H from TableA 

or, create a view and select from it, as shown below:

 CREATE VIEW vTableA as select A, C, D, E, G, H from TableA 
+1
source

You cannot do this. This is '*' or only the fields you specify. This is a big problem? Or is it just that you want something "neat"?

0
source

This is a bit of a pain in the ass, and I went to this forum to find another way to do this, but yes, you are stuck in the definition of each column. You can grab all the columns, though by doing something like this:

 select ',[' + column_name + ']' from information_schema.columns where table_name = 'your_table_name' 

This way you can exclude columns that you don't need pretty quickly. This is especially useful when you have 50+ columns.

0
source

All Articles