MySQL版本5表order_detail tmp_id    customer_id     book_id      amount     ............ re
--------------------------------------------------------------------------
   1          31209         a_3123       100           ...        express
   2          65098         cx_766       1000          ...        air
   3          04564         f_34521      800           ...        ship
   4          31209         cx_766       600           ...        express
这张表我想要查询出除第一列外的所有数据,但是假设我这张表除了tmp_id之外,我不知道其他列的具体名称,这样的SQL语句应该怎么写?请各位大大赐教!
   

解决方案 »

  1.   

    直接查所有列不行吗?
    select * from order_detail
      

  2.   

    select * from order_detail
    直接查所以列吧
      

  3.   

    这个表我另有用处。
    这个表本来就是从一个已存在的表中查询出来的临时表,临时表要和别的查询结果做union,因为多了一个查询时加上去的temp_id,不能直接做union了。
      

  4.   

    两个办法,
    1,在另外一个查询上也加一个没用常量列
    2,利用系统视图把列名查询出来,动态组合sql
      

  5.   

    别的查询结果加temp_id的话union出来可能有重复数据的,因为别的查询结果也是从同一张原始表中查询数据的(别问为什么了,应用比较特殊)
      

  6.   

    像你这样的,应该用存储过程实现了给你个获取列名列表组合的处理思路吧:set @str='';
    select @str :=concat(@str,column_name,',') from information_schema.columns where table_schema='库名' and table_name='表名' and column_name<>'tmp_id';
    select @str;
    select left(@str,char_length(@str)-1) into @column_list;
    select @column_list;
      

  7.   

    select distinct c.column_name from test.order_detail o ,information_schema.columns  c where c.table_name="order_detail" and c.COLUMN_name!="id";
      

  8.   

    没有直接的这种除去某一列或某几列的SQL语句。也不建议在SQL中来实现。如果你不 希望显示某一列,不如在你的程序中为实现。
      

  9.   


    其实可以更简单些。
    select distinct c.column_name from information_schema.columns c where c.table_name='TEST' and c.column_name!='ID'如此可以从表TEST中获得除列名ID之外的所有列