| Author |
slightly OT, sql question
|
|
| Kleist 2005-08-18, 8:59 am |
| 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
| |
| Hilarion 2005-08-18, 8:59 am |
| Kleist <kleist@tlen.pl> wrote:
> 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
Try this:
SELECT MIN( id ) AS res_id
FROM some_table
GROUP BY prod_nr
ORDER BY 1
Hilarion
| |
| Kleist 2005-08-18, 8:59 am |
| Hilarion wrote:
>
> Try this:
>
> SELECT MIN( id ) AS res_id
> FROM some_table
> GROUP BY prod_nr
> ORDER BY 1
>
Thank you very much! Without the ordering works great.
| |
| Hilarion 2005-08-18, 8:59 am |
| > > SELECT MIN( id ) AS res_id
[color=darkred]
> Thank you very much!
No problem.
> Without the ordering works great.
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
|
|
|
|