is there a way to find out if the engine matches your car by the serial number?

if it doesn't match, is there a way to find out where it came from?

thanks