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

How do I repair damaged sql server mdf file database? In previous day my mdf file has got damage due to unknown reasons then I used dbcc chekcdb command but it failed, MDF file is important for me, I don’ know that how to get back mdf file data. Please anyone suggest me?

1287


What are the purpose of Normalisation?

631


Data table as parameter in sql server?

553


How can you check the level of fragmentation on a table?

601


How do you use a subquery to find records that exist in one table and do not exist in another?

540






can we have a nested transaction? : Sql server database administration

492


What is meant by referential integrity?

581


What are clustered and non-clustered index?

540


What are the various editions of sql server 2017 that are available in the market?

501


Define constraints and give an example of their use?

557


How to replace the Query Result 'Null Value' with a text ?

555


Is candidate a key?

525


What is schemabinding a view?

513


What is 2nf normalization form?

605


Can a rule be bound to any column of any data type?

553