If a buyer buys a company (ie the target company) by means of a share sale and purchase (eg using a Share purchase agreement), the buyer takes ownership of shares in the target company. The buyer will acquire the target company with all of its assets and liabilities.
By contrast, if a buyer buys a business as a going concern (ie while it‘s operating and making a profit) by means of an asset sale and purchase, the individual assets of the business concerned will be transferred to the buyer along with the goodwill of the business. This means that the buyer can decide which assets in the target company it will purchase and can leave behind any liabilities, for example, debts and pending litigation.