0

SQL/MySql

I am having one table, in that table 25 columns are there. I need to select 24 columns from the table.

and i don't want to write all column names in select query,for example:

SELECT column1, column2...column24 FROM table1;

Is there any way to get (n-1),(n-2) columns from a select query?

n = number of columns.

user3410226
  • 7
  • 1
  • 7

1 Answers1

0

You can use the information_schema as in:

select GROUP_CONCAT(column_name) from information_schema.columns where table_schema = ? and table_name = ? and ordinal_position < ? order by ordinal_position

Stuff it in a procedure and you are good to go

Lennart
  • 6,000
  • 1
  • 18
  • 31
  • One way I got is : 1.) CREATE TEMPORARY TABLE table2 AS (SELECT * FROM table1); 2.) ALTER TABLE table2 DROP COLUMN password; 3.) SELECT * FROM table2; 4.) DROP TABLE table2; I think this is the fine way. Fine,Thanks – user3410226 May 09 '14 at 07:26
  • Wow, that's the stupidest way of doing it (not referring to the answer). I just hope that people looking for the same thing won't stumble upon this comment, I've no words to stress enough how awful that solution is. – N.B. May 09 '14 at 07:42