I am not sure exactly how you mange purchases and sales, but because you are relating a stock id in one table to a stock id in the second table, you are getting a cross product. for each record in table A, you see every record in table B.
Now if, say table A represent purchases, and table B represents sales, and you are trying to compare the costs with the sales to establish the profit. then you need to structure the data in a different way to answer that question. It's not really a problem of an old database design. If you only buy and sell discrete packages of stocks, then you need a stock package ID as well as the stock ID, and you match Sale 1 to Purchase 1, and Sale 2 to purchase 2. But if Sale 1 might contain part of Purchase 1, and Part of Purchase 2 - and Sale 2 contains the rest of Purchase 2 and part of Purchase 3 - then you can't directly match the purchases and sales. If dividends are reinvested, you are likely to have small increments to the purchases table to represent the DRIPs.
You may be able to aggregate all the purchases to give a total and an average cost, and use the average cost as the purchase value for a sale, but I don't know how you have to report sales and costs, as the profits will affect CGT calculations.
You could have a union query with fields from the two tables in date order, so you can see the flow of purchases and sales to establish the trading results of each sale. If you do that, treat the sales as negative values as it's easier.
Maybe you ought to store the purchase value you are calculating and eliminating on the sales record, as you record each transaction. I know you can evaluate it from first principles, but this might be a case when it's easier to store it. Then you could report the sales without needing the purchases at all.
If you eliminate costs on a FIFO basis, then the value of the investments on hand should be the most recent investments, and the sum of eliminated costs plus current value should equal the total paid, which gives you a good check,
I assume this is something new you are doing, as you must have had this before. If the form does it correctly, see what the form is doing differently to the report.
There is another thread at present talking about valuing trading inventory (widgets, not investments) but it's the same issue. Manging inventory quantity is relatively easy. Managing inventory value is a whole different level of complexity. For each sale, you may need to evaluate which purchases were sold on a FIFO basis in order to evaluate the profit.
I don't know if this is a commercial thing or just to track your own investments, but if it's commercial then the issue of compliance must be pretty important, and you need to be sure you are doing things correctly.