5

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

TableA 

A   B  C  D  E  F G  H

how can i write a query to select all columns except B and F columns. Query result should be

A C D E G H

Do we have something like this

select * from TableA except B, F ?

7 Answers 7

3

No, we don't. You have to use

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

And this is good if you ask me. SELECT * is evil enough.

Sign up to request clarification or add additional context in comments.

Comments

2

Nope, you're stuck with

select a, c, d, e, g, h from TableA

Comments

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

Comments

1

I don't know for sure, but it's definitely better to explicitly specify the columns you want to select. This makes any potential changes to your table easier to live with as you can use aliases etc.

Comments

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

or, create a view and select from that, as below:

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

Comments

0

You can't do this. It is '*' or just the fields you specify. Is this a big problem? Or is it just that you want something "neater"?

Comments

0

It's a bit of a pain in the ass, and I went on this forum to find another way to do this, but yeah, you're stuck defining 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 the columns you don't want pretty quickly. It's especially useful when you have like 50+ columns.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.