By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,919 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,919 IT Pros & Developers. It's quick & easy.

need an sql query for the following situation

P: 58
i need a query to get a collection ...
Following is the situation.
ive got a collection in which item of each element is different.
but each element has an item_id tat can be same.all these elements have weightage... i need to get elements with unique item_id and max weightage.
ie;
i got a collection of elements such as

e1 with item_id as 1 and weightage 7
e2 with item_id as 2 and weightage 10
e3 with item_id as 1 and weightage 8
e4 with item_id as 5 and weightage 10
e5 with item_id as 6 and weightage 10
e6 with item_id as 1 and weightage 6
so my result collection should contain the elements
e3 with item_id as 1 and weightage 8
e2 with item_id as 2 and weightage 10
e4 with item_id as 5 and weightage 10
e5 with item_id as 6 and weightage 10


can i get this in a single sql query? please help
Jun 15 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 534
Try this query
Expand|Select|Wrap|Line Numbers
  1. SELECT item_id, max(weightage) FROM tabName group by item_id 
  2.  
Jun 15 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.