Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Query

$
0
0

Hi

Table A

No      Name        Acct

1        King          2256

2                         2256

3        Lisa           1111

4        Lisa           1111

5                          2222

6                          2222

7                          8888

8       Linda          8888

I need to write a query to get the duplicate records based on acct field from table A.

conditions :

* Select the record with name is not null.  Eg . Row 1 and 2    .. The output should have row 1

* If name is present in both records then select the top 1.   Eg : Row 3 and 4... The output should have row 3

* If name is null in both rows then select the top 1.   Eg :row 5 and 6 .. The output should have row 5

*Select the record with name is not null . Eg Row 7 and 8 . The output should have 8.

Expected output.

No      Name        Acct

1        King          2256

3        Lisa           1111

5                          2222

8       Linda          8888


Please help


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>