0

Possible Duplicate:
SQL exclude a column using SELECT * [except columnA] FROM tableA?

I have a table and this table contain 30 columns and I get only those columns name who they are required me with *.

My question is how do I avoid rest of columns name?

For example, result required if possible in MySQL:

SELECT *, AVOID('col_13,col_14') FROM `table`

AVOID is not a function of MySQL I just explain through this.

Why I want this? I required only 20 columns name for a home page and I don't write a query like this because I want optimize or shorter way like *.

SELECT col_1,col_2,....col_20 FROM `table`

This is possible in MySQL.

Community
  • 1
  • 1
Query Master
  • 6,989
  • 5
  • 35
  • 58
  • Please do not edit out duplicate links if they are automatically added to your posts - this was the reason the question was closed some years back. If you do not believe the question was a duplicate, please cast a reopen vote, or post on Meta. – halfer Dec 30 '16 at 00:35

2 Answers2

2

No it's not possible. You need to enumerate all required fields

zerkms
  • 249,484
  • 69
  • 436
  • 539
0

Try this Query

SET @SQL = CONCAT('SELECT ', (SELECT REPLACE(GROUP_CONCAT(COLUMN_NAME), 'col_13,col_14,', '') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'table_name' ), ' FROM table_name');

PREPARE stmt1 FROM @SQL;
EXECUTE stmt1;
Query Master
  • 6,989
  • 5
  • 35
  • 58