Select all columns except one in MySQL?

后端 未结 30 2886
后悔当初
后悔当初 2020-11-22 00:46

I\'m trying to use a select statement to get all of the columns from a certain MySQL table except one. Is there a simple way to do this?

EDIT: There are 53 columns i

30条回答
  •  心在旅途
    2020-11-22 01:27

    Im pretty late at throing out an answer for this, put this is the way i have always done it and frankly, its 100 times better and neater than the best answer, i only hope someone will see it. And find it useful

        //create an array, we will call it here. 
        $here = array();
        //create an SQL query in order to get all of the column names
        $SQL = "SHOW COLUMNS FROM Table";
            //put all of the column names in the array
            foreach($conn->query($SQL) as $row) {
                $here[] = $row[0];
            }
        //now search through the array containing the column names for the name of the column, in this case i used the common ID field as an example
        $key = array_search('ID', $here);
        //now delete the entry
        unset($here[$key]);
    

提交回复
热议问题