Deductions & credits

This is answered in detail, with a diagram, in chapter 4 of publication 463.

https://www.irs.gov/forms-pubs/about-publication-463

 

The short answer is you can claim the mileage from job location 1 to location 2 on the same day, but you can't claim the mileage from job 2 to your home, as that is considered part of your non-deductible commute.