Home > Archive > Microsoft SQL Server forum > August 2005 > need help with query









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author need help with query
Donna

2005-08-23, 9:23 am

Hi,

I have a table with composite key: ID1 and ID2 and it also has a
priority field.

I want to get all the information for all records with the minimum
priority group by ID2. How can I achieve that?

Thanks.

Donna

Madhivanan

2005-08-23, 9:23 am


Post table structures, sample data and the result you want

Madhivanan

Donna

2005-08-23, 11:24 am

specifically when I do the following, I lose id2:

select min(priority) as priority, id1 from table t
group by id1

I want it to return id1, id2, priority where it is the min(priority)
group by id1

Madhivanan

2005-08-23, 11:24 am

Try this

Select T1.id1,T1.id2,T2.priority from tablet T1
inner join (select min(priority) as priority, id1 from table t
group by id1 ) T2 on t1.id=T2.id and t1.id2=T2.id2

Madhivanan

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com