Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello, I need help with my query. I

Status
Not open for further replies.

Magnolia1

Technical User
May 12, 2016
4
US
Hello, I need help with my query. I built 2 tables: Table 1: sub account number, account name, amount paid (Record one: abc, Tree, 100; Record two: abc, Tree, 200) and Table 2: account number, sub account number, account name (Record one: 1122, abc, Tree; Record Two: 3344, acb, Tree). I joined them by sub account number and account name. I was looking to get the following answer: Account Number; Sub Account Number; Account Name; Amount;
1122 abc Tree 100
3344 abc Tree 200
but I got additional records that I do not need.
Account Number; Sub Account Number; Account Name; Amount;
3344 abc Tree 100
1122 abc Tree 100
3344 abc Tree 200
1122 abc Tree 200
How can I get read of theses additional records?
Thank you for your responses. :)
 
Can you go to sql view and post your actual SQL. If I understand correctly you may have not joined the tables and actually created a cartesian products. Two tables without a join give you each record in table one joined to each record in table two
 
Hello MajP,
Thank you for your response. The SQL for my query is as follows:
SELECT Table2.[Account Number], Table1.[Sub Account Number], Table1.[Account Name], Table1.Amount
FROM Table1 LEFT JOIN Table2 ON (Table1.[Sub Account Number] = Table2.[Sub account number]) AND (Table1.[Account Name] = Table2.[Account Name]);

This is a mock up query. But it is an accurate reproduction of my issue. The tables are imported from 2 different sources and missing any/all unique values or anything that I could potentially use as a unique value. I have to come up with a work around.
Thank you again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top