我试图使用一个选择语句从某个MySQL表中获得除一个以外的所有列。有什么简单的方法吗?

编辑:在这个表格中有53列(不是我的设计)


当前回答

我同意@Mahomedalid的回答,但我不想做一些准备好的语句,我不想输入所有的字段,所以我有一个愚蠢的解决方案。

去phpmyadmin->sql->select表,它转储查询:复制,替换和完成!:)

其他回答

我很晚才想出一个答案,坦率地说,这是我一直在做的事情,它比最好的答案要好100倍,我只希望有人能看到它。发现它很有用

    //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]);

我同意只选择*是不够的,如果你不需要,正如在其他地方提到的,是一个BLOB,你不希望有这个开销。

我会用所需的数据创建一个视图,然后您可以轻松地选择*——如果数据库软件支持它们的话。否则,将大量数据放到另一个表中。

是的,尽管根据表的不同,I/O可能会很高,但我找到了一个解决方案。

SELECT *
INTO #temp
FROM table

ALTER TABLE #temp DROP COlUMN column_name

SELECT *
FROM #temp

视图在这种情况下工作得更好吗?

CREATE VIEW vwTable
as  
SELECT  
    col1  
    , col2  
    , col3  
    , col..  
    , col53  
FROM table

即使要查询所有列,也最好指定要查询的列。

因此,我建议您在语句中写下每一列的名称(不包括您不想要的列)。

SELECT
    col1
    , col2
    , col3
    , col..
    , col53

FROM table