A table contains list of customers and his city with other
details. Each customer has a unique number and the table
consists millions of data. Query is: I want to retrieve 10
customers from each city, no script, only from single query?

Answer Posted / asim

select id,addressid,city
from
(
SELECT ROW_NUMBER() OVER (partition by city Order by
addressid) ID,AddressID,City
FROM person.Address A
WHERE City IN
(select city from person.address group by City

) )a
where a.ID <11
order by City,ID

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can two tables share a primary key?

716


What are the events recorded in a transaction log?

731


Can we use having clause without group by?

734


What is difference between join and natural join?

647


if you encounter this kind of an error message, what you need to look into to solve this problem? : Sql server database administration

721






How to get the definition of a stored procedure back?

708


Do you know what is raid and what are different types of raid configurations? : SQL Server Architecture

732


What is the main purpose of having conversation group?

662


How you trouble shoot when any job fails

1675


Is there any difference between primary key and unique with the not null condition?

702


What are the essential components of sql server service broker?

761


How does recursive cte works in sql server?

711


What is the sql server 2000 version number?

771


Can you name some of the dml commands in sql?

755


Can you get second highest salary from the table?

724