Professional Web Applications Themes

slightly OT, sql question - PHP Development

Hello, I have a table like this: ID | prod_nr | rate ----|----------|------------ 1 | 23 | 8 2 | 29 | 11.3 3 | 230 | 3 4 | 23 | 16.2 5 | 23 | 4 I am new in sql, and don`t know how to get list of ID's for distinct list of prod_nr. I need to have the result like this. res_id ------- 1 2 3 Thanks in advance for any clue in this question...

  1. #1

    Default slightly OT, sql question

    Hello,

    I have a table like this:

    ID | prod_nr | rate
    ----|----------|------------
    1 | 23 | 8
    2 | 29 | 11.3
    3 | 230 | 3
    4 | 23 | 16.2
    5 | 23 | 4

    I am new in sql, and don`t know how to get list of
    ID's for distinct list of prod_nr. I need to have the result
    like this.

    res_id
    -------
    1
    2
    3

    Thanks in advance for any clue in this question
    Kleist Guest

  2. #2

    Default Re: slightly OT, sql question

    Kleist <pl> wrote: 


    Try this:

    SELECT MIN( id ) AS res_id
    FROM some_table
    GROUP BY prod_nr
    ORDER BY 1


    Hilarion
    Hilarion Guest

  3. #3

    Default Re: slightly OT, sql question

    Hilarion wrote:
     


    Thank you very much! Without the ordering works great.
    Kleist Guest

  4. #4

    Default Re: slightly OT, sql question

    > > SELECT MIN( id ) AS res_id [/ref]
     

    No problem.

     

    Should also work with ordering (if you need it), but
    depending on SQL engine you are using you may have to
    change "ORDER BY 1" to "ORDER BY res_id" or
    "ORDER BY MIN( id )".


    Hilarion
    Hilarion Guest

Similar Threads

  1. Slightly OT - Database Question
    By Andy in forum Dreamweaver AppDev
    Replies: 6
    Last Post: February 25th, 02:07 PM
  2. [Slightly OT] Is there a way?
    By e n | c k m a in forum PHP Development
    Replies: 1
    Last Post: November 12th, 11:22 PM
  3. php oop .. slightly ot
    By Chris Mosser in forum PHP Development
    Replies: 5
    Last Post: August 31st, 02:37 PM
  4. slightly ot
    By Chris Mosser in forum PHP Development
    Replies: 2
    Last Post: August 1st, 07:31 AM
  5. plain paper for Canon i950 slightly OT printer question
    By what to do in forum Photography
    Replies: 1
    Last Post: July 11th, 09:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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