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

后端 未结 30 3017
花落未央
花落未央 2020-11-21 23:15

We all know that to select all columns from a table, we can use

SELECT * FROM tableA

Is there a way to exclude column(s) from a table witho

30条回答
  •  梦毁少年i
    2020-11-22 00:00

    The best way to solve this is using view you can create view with required columns and retrieve data form it

    example
    
    mysql> SELECT * FROM calls;
    +----+------------+---------+
    | id | date       | user_id |
    +----+------------+---------+
    |  1 | 2016-06-22 |       1 |
    |  2 | 2016-06-22 |    NULL |
    |  3 | 2016-06-22 |    NULL |
    |  4 | 2016-06-23 |       2 |
    |  5 | 2016-06-23 |       1 |
    |  6 | 2016-06-23 |       1 |
    |  7 | 2016-06-23 |    NULL |
    +----+------------+---------+
    7 rows in set (0.06 sec)
    
    mysql> CREATE VIEW C_VIEW AS
        ->     SELECT id,date from calls;
    Query OK, 0 rows affected (0.20 sec)
    
    mysql> select * from C_VIEW;
    +----+------------+
    | id | date       |
    +----+------------+
    |  1 | 2016-06-22 |
    |  2 | 2016-06-22 |
    |  3 | 2016-06-22 |
    |  4 | 2016-06-23 |
    |  5 | 2016-06-23 |
    |  6 | 2016-06-23 |
    |  7 | 2016-06-23 |
    +----+------------+
    7 rows in set (0.00 sec)
    

提交回复
热议问题