For US (which you didn't actually say but IRS implies) in addition to what Bob said:
You can choose among usually three options when you sell:
FIFO -- the oldest open lot(s)
LIFO -- the newest open lot(s)
'specific identification' -- you can choose any open lot(s). If you have only two lots, as in your example, you never need this option, because those ...
FIFO = First In, First Out
LIFO = Last in, First Out
You can designate to your broker what accounting method you want for closed positions (FIFO, LIFO or share designation).
The IRS requires that your broker verifies that the specific shares that are sold. Without that confirmation, your broker will default to FIFO.
A dividend represents a portion of a company’s earnings and the amount that you receive depends on the payout rate and the number of shares that you own.
A capital gain is the profit from purchasing a security at one price and selling it at a higher price.
An area of confusion for some is when a mutual fund makes a capital gains distributions at the end of ...