Quantcast
Channel: SQL Server Compact Forum
Viewing all articles
Browse latest Browse all 193

how to select the odd records

$
0
0

I have this tableA

PK, debit, Credit, account

1, 1, null, Account1
2, null, 1, Account1
3, 1, null, Account1
4, 1, null, Account2


I want you to help me a sql command to select the 3rd and 4th records. Means that I want all records except the records with debit=credit & Account=Account

My sql command :

SELECT [TableA].*
FROM [TableA] LEFT JOIN
(SELECT [TableA_3].*
FROM [TableA] AS [TableA_3] INNER JOIN
[TableA] AS [TableA_1] 
ON [TableA_3].debit = [TableA_1].credit 
AND [TableA_3].account = [TableA_1].account)
AS [TableA_2] 
ON [TableA].pk = [TableA_2].pk
where [TableA_2].pk is NULL

only select the 4th record because the TableA_2 is contained first 3 records.

Thanks for your help.



Viewing all articles
Browse latest Browse all 193

Trending Articles



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