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 / grace

SELECT A.*
FROM dbo.T1 A
WHERE CustomerID IN
(SELECT TOP 10 CustomerID FROM dbo.T1 WHERE City=A.City)

Is This Answer Correct ?    24 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the events recorded in a transaction log?

508


What is the difference between varchar and varchar types?

568


What are the kinds of subquery?

533


in the physical file layout, where should the transaction log be stored in relation to the data file?

537


What is the command to change the recovery model?

571






What is Service Broker in sql server 2012?

624


How do you delete duplicate records in sql server?

515


What are the differences between sql server and mysql.

534


Beginning with sql server version 7 0, a new enhanced data type nchar was added what type of data is supported with this data type?

520


How do I port a number to sql server?

508


What xml support does the sql server extend?

533


What is the federation in sql azure?

79


How to execute stored procedure in select statement sql server?

539


What are the disadvantages of using the stored procedures?

553


In case you have filters in your report, when filters will be applied in cached report instance?

81