Write a sentence with a comma that separates different clauses in a compound or complex sentence

I went to the store, but I forgot to buy milk.

why is the comma needed in this sentence?

The comma is needed in this sentence because it separates two independent clauses connected by the coordinating conjunction "but."

Write a sentence with a comma that separates items in a list

I need to buy apples, bananas, and oranges from the grocery store.