mainrotor
asked on
I need help with a query
Hi Experts,
I have TableA and TableB in my SQL Server 2012 database. I want to run a query that returns the AccountNo, and Amount that exists in TableB, but not in TableA. The table can be compared by using the AccountNo.
Example of raw data.
TableA
AccountNo
1001
1002
TableB
AccountNo Amount
1001 100.00
1002 250.00
1003 175.00
1003 200.00
1004 145.00
I want the result to be AccountNo in TableB only:
AccountNo Amount
1003 175.00
1003 200.00
1004 145.00
I have TableA and TableB in my SQL Server 2012 database. I want to run a query that returns the AccountNo, and Amount that exists in TableB, but not in TableA. The table can be compared by using the AccountNo.
Example of raw data.
TableA
AccountNo
1001
1002
TableB
AccountNo Amount
1001 100.00
1002 250.00
1003 175.00
1003 200.00
1004 145.00
I want the result to be AccountNo in TableB only:
AccountNo Amount
1003 175.00
1003 200.00
1004 145.00
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Using the Left Join as suggested above is more efficient than using a subquery.