group by in sql server [Resolved]

Posted by Venkatesh under Sql Server on 4/29/2011 | Points: 10 | Views : 1225 | Status : [Member] | Replies : 5
Hi

i have table which is having 5 records
like
id|name|address
1 a hyd
2 b viz
3 a hyd
4 b viz

i need out put as

id|name|address
1 a hyd
2 a hyd
3 b viz
4 b viz

how to get in the query?
Thanks
Venkatesh.P




Responses

Posted by: Santoshkumar on: 4/29/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi venkatesh

u can write query like this.

select id, ename, addres from addr
order by ename

Its working. I checked it.

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 4/29/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Venkatesh


write this query . .


Select * from tablename Group by Name

Best Regard's
Prabhakar

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: PandianS on: 4/29/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi

If you using SQL Server 2005 and Later then....
Select ROW_NUMBER() Over(Order by Name,[Address]) [Id],name,[address] from tablename
@Prabhakar: Do you think your script will work fine ?, Kindly check.... :)
Your script will work fine only when the Table has only one column(Name). But, here Venkatesh has 3 columns in the table. correct ? :)

Cheers


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 4/29/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi PandianS . .


yeh u say right . . i put wrong query . . i just confuse . . so i put group by example . .. .
my mistake . . i am not judge . . full requirement . .


Best Regard's
Prabhakar

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhaarat287 on: 5/3/2011 [Member] Starter | Points: 25

Up
0
Down
I am agree with PandianS.
This is perfect solutions for your problem.


Bhaarat

http://ransandeep.blogspot.com

Venkatesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response