Do a Socratic search for a similar question How does the formation of coal differ from that of natural gas and oil? which has already been answered.
Similarities: they are both formed from organic remains and both form under enormous pressures in a sedimentary sequence.
Differences: coal is formed from land-based plants in bogs and coastal swamps while oil and gas are derived from tiny marine organisms such as algae and phytoplankton.