4

I want to select 15 columns from a table of 20 columns. Is there a way to exclude those 5 columns instead of specifying other 15 columns.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Karthik
  • 317
  • 2
  • 5
  • 13

4 Answers4

3

No, you either have to select them all (*) or list the 15.

cletus
  • 616,129
  • 168
  • 910
  • 942
2

Create a view containing only the columns you'd like to get.

Puppe
  • 4,995
  • 26
  • 27
1

I don't think it's possible, and it is not such a good idea. What if your columns change later? Than your results will not correspond to your objects. If your question comes from plain laziness than you probably should reconsider.

Egor Pavlikhin
  • 17,503
  • 16
  • 61
  • 99
  • 1
    This is possible: [check this answer out.](http://stackoverflow.com/questions/2365972/how-can-i-select-from-a-table-in-mysql-but-omit-certain-columns/13808457#13808457) Though it still may not be a good idea if your columns changing creates a possibility of something breaking. – donL Dec 10 '12 at 20:26
  • If the columns change later he will always have to change the query either way. Actually, for the query itself, it's 3 times as likely he won't have to change it; just have to take care of the treatment of the data afterwards, if it's not a dynamic thing. – webdreamer Sep 18 '15 at 10:22
0

Include 15 columns than excluding 5. It is a standard practice too.

(Also try to avoid *, it is not standard eventhough it works)

NinethSense
  • 8,824
  • 2
  • 23
  • 23