SELECT * / Order of Columns

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default SELECT * / Order of Columns

    Hey guys, is there a way to re-arrange the order of columns when using SELECT *
    - I don't normally use SELECT *, but am forced to in a current situation and
    would like to re-arrange the order of the columns.

    dj shane Guest

  2. Similar Questions and Discussions

    1. How to programatically order columns in anAdvancedDataGrid
      Hello all, I have no problems programmatically ordering columns in a standard DataGrid - however doing the same in an AdvancedDataGrid is proving...
    2. Selecting all columns, but in a different order in SELECT statement
      Thanks, i thought that was the case... just wanted to confirm it before i started working on it. Alex "Vishal Parkar" <vgparkar@hotmail.com>...
    3. Pad strings/concatenate columns to simulate data columns in ASP select box with SQL Server 2K
      Dale, Cast all the data to fixed character data type in your select statement. For example: select cast(au_id as char(12)) +...
    4. SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
      Following is my stored procedure. If I take the DISTINCT out then everything works fine. BUT I need the distinct because it returns duplicate...
    5. SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items mustappear in the select list if SELECT DISTINCT is specified.
      Dan, You should be able to do this: SELECT Id, FaxID, ReceivedTime, Pages FROM ( SELECT DISTINCT .Id AS Id,
  3. #2

    Default Re: SELECT * / Order of Columns

    Order by and/or group by should give you what you want on your output.
    rmorgan Guest

  4. #3

    Default Re: SELECT * / Order of Columns

    In what order do you want them? You can use a list function to sort them
    alphanumerically, but (I think) that's the way they are returned in
    query.ColumnList. If you need them in a certain order, but not
    alphanumerically, that would signify that you knew what fields are being
    returned by the query, and you would have to apply rules based on which column
    list you expected.

    philh Guest

  5. #4

    Default Re: SELECT * / Order of Columns

    rMorgan, sorry not order by veritically, I ment ordering the columns

    Example, SELECT * FROM TABLE

    Brings back the columsn, Name, Address, Height, Weight, EyeColor in that order
    from the database.

    But I want them in a different order. Perhaps, Height, Weight, Name, Address,
    EyeColor.

    Again, I hate select *, but I must use it in this case.

    dj shane Guest

  6. #5

    Default Re: SELECT * / Order of Columns

    And will you know the field names and desired sorting order in advance?

    Originally posted by: dj shane
    rMorgan, sorry not order by veritically, I ment ordering the columns

    Example, SELECT * FROM TABLE

    Brings back the columsn, Name, Address, Height, Weight, EyeColor in that order
    from the database.

    But I want them in a different order. Perhaps, Height, Weight, Name, Address,
    EyeColor.

    Again, I hate select *, but I must use it in this case.



    Dan Bracuk Guest

  7. #6

    Default Re: SELECT * / Order of Columns

    1. Why do you HAVE to use select *? Bad practice....
    2. Why do you care what order the columns are selected? It really makes no difference...
    _silence Guest

  8. #7

    Default Re: SELECT * / Order of Columns

    To specify the order of your columns you need to list them explicitly in your
    select list.

    Ie, if SELECT * returns columns in A, B, C order but you want them in B A C or
    C B A or something then you do:

    SELECT B, A, C FROM ...
    SELECT C, B, A FROM..

    If you specify the columns you want they will be returned in the order you
    specify. If there are too many columns for you to list them like this, you have
    a bigger problem, your DB schema sucks.

    Matt.Stuart Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139