1

I want to query everything, Like: SELECT * FROM

but I want to exclude two columns because their not necessary, but there's too many columns I need to just type it all one by one. Is there an exclude keyword or except keyword or something in SQL or MYSQL?

Howdy_McGee
  • 10,422
  • 29
  • 111
  • 186
  • 2
    possible duplicate of [Select all columns except one in MySQL?](http://stackoverflow.com/questions/9122/select-all-columns-except-one-in-mysql) – The Scrum Meister Jul 22 '11 at 17:15
  • 1
    duplicate of http://stackoverflow.com/questions/729197/sql-exclude-a-column-using-select-except-columna-from-tablea – sap Jul 22 '11 at 17:16

2 Answers2

3

No. It's better practice to type out all of the fields as opposed to SELECT * FROM ... anyway.

If you're going to be a programmer, you may as well get used to typing :)

Tom Studee
  • 10,316
  • 4
  • 38
  • 42
  • 1
    hahaha that is true but as a programmer you need to also keep your code short and sweet to avoid future load problems/server hang ups ;) – Howdy_McGee Jul 22 '11 at 17:18
  • Trust me: having the column names all viewable in the query makes your code much more readable and maintainable. – TehShrike Jul 22 '11 at 17:21
1

Yes, you must type them all out.

Or, if there really are that many you can do it programatically.

SHOW COLUMNS FROM `tablename`

Will give you the list of columns. Use whatever language you are using to pull them out and build the query with them.

Of course, you have to make sure the column names are escaped (what if you have a column name called select?).

DaedalusFall
  • 8,335
  • 6
  • 30
  • 43