Select Table and count IDENTITY

select   name, tel from User  where sex='f'


name, tel
-----------
Vivia  008-855
Jan    854-526

how do i select  data  like this ?

key , name, tel
--------------
1 Vivia  008-855
2 Jan    854-526
3  





ezroyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SQL_StuCommented:
You could try:

Select count(*) as key, name, tel
from User
where sex = 'F'
group by name, tel
order by count(*)

0
SQL_StuCommented:
oops, no, that won't work!!  I misread your question...
0
Thandava VallepalliCommented:
select name, tel, ( select count(*) from user where  name <= t1.name )
from User  t1
where sex='f'
order by name

itsvtk
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

rdrunnerCommented:
Well actually the "key" should be the "same" for both male and female entries.

If your table looks like this:

key , name, tel
--------------
1 Vivia  008-855
2 Sue    854-526
3 Jan    854-526
4 Mary 555-555

then your query should return  

1 Vivia  008-855
3 Jan    854-526

The key should define the row in the database and not the row in the returned result. If you take the key of the result for example, then there could be another entry added between Jan and Vivian and the IDs in the result changed. If you return the true IDs in the DB you will still be able to modify "Jan" with the ID of 3 since the new guy gets a new ID (5)

Hope this makes sense...
0
Thandava VallepalliCommented:
or this..

select name, tel, ( select count(*) from user where  tel <= t1.tel )
from User  t1
where sex='f'
order by tel

itsvtk


0
Thandava VallepalliCommented:
sorry... i forgot to consider sex condition.... in subquery

select name, tel, ( select count(*) from user where  tel <= t1.tel and sex = 'f' )
from User  t1
where sex='f'
order by tel


itsvtk
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ezroyAuthor Commented:
i dont have ' Key ' filed,
i just wnat to count   result ,
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.