Get accounts from SummaryTable to every record in DetailTable

X

XP

Assuming:

SummaryTable contains summary info in which the value of several items have
been added together for each transaction. DetailTable contains detailed info
in which a separate record is included for every item composing each
transaction.

SummaryTable, with many fewer rows, includes an account number. The TranID
is the primary key in both tables and relates the transactions. I need a
query that pulls detailed information from DetailTable, but includes an
account number for every item in the query from SummaryTable. For now at
least, I just want all records from the DetailTable.

Can someone please post generic example SQL how I would do this?

Thanks much in advance.
 
M

Marshall Barton

XP said:
Assuming:

SummaryTable contains summary info in which the value of several items have
been added together for each transaction. DetailTable contains detailed info
in which a separate record is included for every item composing each
transaction.

SummaryTable, with many fewer rows, includes an account number. The TranID
is the primary key in both tables and relates the transactions. I need a
query that pulls detailed information from DetailTable, but includes an
account number for every item in the query from SummaryTable. For now at
least, I just want all records from the DetailTable.


If a transaction can have multiple details, then TranID can
not be the detail table's primary key. Maybe you meant that
it is part of the PK??

Regardless, try joining the two table on the TranID field

SELECT S.TranID, S.TranTotal, D.AccountNum, D.Amount
FROM SummaryTable As S INNER JOIN DetailTable As D
ON S.TranID = D.TranID
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top