Hide mysql select field

2

Well I'm used to doing the select as follows:

select nome, idade,cidade from cadastro

This select returns me the fields name, age, city.

But I want to do the opposite, I have a table with many fields and I want the select to return all the fields, except the fields nome and idade .

Is it possible to do this?

    
asked by anonymous 18.08.2017 / 14:26

2 answers

2

You need permissions, there is no specific command but you can do this:

SET @sql = CONCAT('SELECT ', (SELECT REPLACE(GROUP_CONCAT(COLUMN_NAME), 
'<colunas_omitidas>,', '') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '<table>' 
AND TABLE_SCHEMA = '<database>'), ' FROM <table>');

    PREPARE stmt1 FROM @sql;
    EXECUTE stmt1;

Changing <table> , <database> and <colunas_omitidas>

I do a lot of work because it has tables with more than 60 columns

    
18.08.2017 / 14:50
1

You can not do this because there is no modifier with this functionality provided in SELECT , at least not up to version 5.7:

SELECT
    [ALL | DISTINCT | DISTINCTROW ]
      [HIGH_PRIORITY]
      [STRAIGHT_JOIN]
      [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
      [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr ...]
    [FROM table_references
      [PARTITION partition_list]
    [WHERE where_condition]
    [GROUP BY {col_name | expr | position}
      [ASC | DESC], ... [WITH ROLLUP]]
    [HAVING where_condition]
    [ORDER BY {col_name | expr | position}
      [ASC | DESC], ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [PROCEDURE procedure_name(argument_list)]
    [INTO OUTFILE 'file_name'
        [CHARACTER SET charset_name]
        export_options
      | INTO DUMPFILE 'file_name'
      | INTO var_name [, var_name]]
    [FOR UPDATE | LOCK IN SHARE MODE]]

Reference: link

    
18.08.2017 / 14:50