问题
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 ?
回答1:
Nope, you're stuck with
select a, c, d, e, g, h from TableA
回答2:
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.
回答3:
select A, C, D, E, G, H from TableA
回答4:
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.
回答5:
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
回答6:
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"?
回答7:
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.
来源:https://stackoverflow.com/questions/1839075/sql-query-to-select-all-columns-in-a-table-except-two-columns