I tried to find information about joining tables without foriegn keys, but it seems like you always need to create a foreign key. I cannot modify these tables to do this, and I must report data that is already being produced. The following is some of the data in the tables to illustrate the problem.
Table A Journal Account Debit Credit Sequence -------------------------------------------------- 87041 150-00 100.00 0.00 16384 87041 150-10 0.00 100.00 32768 87041 150-00 50.0 0.0 49152 87041 210-90 0.0 50.0 65536
Then the second table, tracking additional bits of information, is in many respects identical, but does not have a sequence number that would correctly associate positions. It has its own serial number, which is not connected.
Table B Journal Account Label Artist Sequence -------------------------------------------------- 87041 150-00 Label02 Artist12 1 87041 150-10 Label09 Artist03 2 87041 150-00 Label04 Artist01 3 87041 210-90 Label01 Artist05 4
For now, the best I can think of is to join the Journal and Account, but that duplicates the entries. I got close by playing with grouping and max () by sequence number, but the result was that not all duplicates are deleted for journal entries with a very large number of rows, and the first match from the second table is always displayed for lines that have one account.
Closest - but bad - result Journal Account Debit Credit Sequence Label Artist ---------------------------------------------------------------------- 87041 150-00 100.00 0.00 16384 Label02 Artist12 87041 150-10 0.00 100.00 32768 Label09 Artist03 87041 150-00 50.0 0.0 49152 Label02 Artist12 <-- wrong 87041 210-90 0.0 50.0 65536 Label01 Artist05
How can I join tables in such a way that duplicates are excluded, as well as to display the correct label and artist? It seems to me that I should create a query that knows that one of the records from table B has already been used when record 49152 from table A is looking for a match.
EDIT:
@Justin Crabtree A.Sequence will be the order in which the positions were entered. Thus, the user could enter the last line in the example first, then the first line, then the third and, finally, the second.
@Edper Microsoft SQL Server ... hmm, today I canβt remotely to the client machine ... otherwise I would provide a version.
@Abe Miessler yes you are right.
As soon as I can return to the server, I will try your offer @pkuderov