How to group by and select only the specific item in a group

  Kiến thức lập trình
test_run_id test_id suite_id exe_length message
4201 32 39 11 Hub Status does1
4201 32 39 17 Hub Status does3
4201 32 39 17 Hub Status does4
4201 32 39 18 Hub Status does7
4200 32 39 11 Hub Status does8
4197 32 39 11 Hub Status does0
4196 32 39 17 Hub Status doesn14
4196 32 39 18 Hub Status does134
4195 NULL 31 14 Hub Status does123
4187 7 12 35 Hub Status d34567
4187 7 12 35 Hub Status 345566

I have the table above, how can i select for each matching test_run_id, test_run_id and suite_id the message with the minimum length

Example:
for test_run_id=4201, test_id=32, suite_id=39, I want the message where exe_length is minimum (11). i.e message = "Hub Status does1"

when the column values are hardcoded it easy:

select  message
    from log_message_view_uat
    where test_run_id= 4201 and test_id=32 and suite_id=39 and exe_length = (select min(exe_length) from log_message_view_uat
    where test_run_id= 4201 and test_id=32 and suite_id=39)

How can i get the same message per column parameter in the database

1

LEAVE A COMMENT