![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all! In a statement I want to find the IDENTITY-column value for a row that has the smallest value. I have tried this, but for the result i also want to know the row_id for each. Can this be solved in a neat way, without using temporary tables? CREATE TABLE some_table ( row_id INTEGER NOT NULL IDENTITY(1,1) PRIMARY KEY, row_value integer, row_name varchar(30) ) GO /* DROP TABLE some_table */ insert into some_table (row_name, row_value) VALUES ('Alice', 0) insert into some_table (row_name, row_value) VALUES ('Alice', 1) insert into some_table (row_name, row_value) VALUES ('Alice', 2) insert into some_table (row_name, row_value) VALUES ('Alice', 3) insert into some_table (row_name, row_value) VALUES ('Bob', 2) insert into some_table (row_name, row_value) VALUES ('Bob', 3) insert into some_table (row_name, row_value) VALUES ('Bob', 5) insert into some_table (row_name, row_value) VALUES ('Celine', 4) insert into some_table (row_name, row_value) VALUES ('Celine', 5) insert into some_table (row_name, row_value) VALUES ('Celine', 6) select min(row_value), row_name from some_table group by row_name |
#3
| |||
| |||
|
|
In a statement I want to find the IDENTITY-column value for a row that has the smallest value. I have tried this, but for the result i also want to know the row_id for each. Can this be solved in a neat way, without using temporary tables? |
![]() |
| Thread Tools | |
| Display Modes | |
| |