Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
GroupId          GeneralId          name
3                 10000              aaaaa
3                 10000              bbbbb
3                 10000              ccccc
3                 10000              ddddd
2                 50000              eeeee
2                 50000              fffff
2                 50000              ggggg
2                 50000              hhhhh
1                 10000              aaaaa
1                 10000              bbbbb
1                 10000              ccccc
1                 10000              ddddd


I want general id's max GroupId
Expected output is
C#
GroupId
3
2


I tried below queries, but i did not get output
C#
1. select MAX(GroupId) from tbl where GeneralId in ('3','2') Group by GroupId

2. select GroupId from tbl where GeneralId in ('3','2') Group by GroupId having GroupId=MAX(GroupId)

Please tell me the query.

Sorry, the query what i put above was not correcr,i tried
1. select MAX(GroupId) from tbl where GeneralId in ('50000','10000') Group by GroupId
2. select GroupId from tbl where GeneralId in ('50000','10000') Group by GroupId having GroupId=MAX(GroupId)

but i got output as below

GroupID
1
2
3
Posted
Updated 10-Sep-14 23:34pm
v3
Comments
ChauhanAjay 11-Sep-14 5:08am    
Change the first query from
select MAX(GroupId) from tbl where GeneralId in ('3','2') Group by GroupId
to
select MAX(GroupId) from tbl where GeneralId in ('50000','10000') Group by GroupId

and the above query should give you the result
kalaivanan from Bangalore, India 11-Sep-14 5:41am    
after tried below query
select MAX(GroupId) from tbl where GeneralId in ('50000','10000') Group by GroupId
Am getting output as below
GroupID
1
2
3
but i need
GroupId
2
3
Magic Wonder 11-Sep-14 6:06am    
Have you tried solution 1?

1 solution

Try:
SQL
SELECT MAX(GroupID) 
FROM tbl 
GROUP BY GeneralId
 
Share this answer
 
Comments
Gihan Liyanage 11-Sep-14 5:16am    
Best understanding.. 5d

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900